Skip to content

Commit

Permalink
feat(load-click): added disabled @input
Browse files Browse the repository at this point in the history
  • Loading branch information
flauc committed Feb 18, 2020
1 parent 9c78f8c commit 49f5b6f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,12 @@ Listens for the emitted click event on the target element and add loading class.

| name | type | default | description |
| ------------------------ | --------------- | --------- | ---------------------------------------- |
| jpLoadClick | Observable<any> | false |
| jpLoadClick | Observable<any> | null |
| loadClickClass | string | 'loading' |
| loadClickStopPropagation | boolean | false |
| loadClickEventType | string | 'click' |
| loadClickPreventDefault | boolean | false |
| loadClickStopPropagation | boolean | false | Should `stopPropagation` be called.
| loadClickEventType | string | 'click' |
| loadClickPreventDefault | boolean | false | Should `preventDefault` be called.
| disableAttribute | boolean | true | Should the disabled attribute be attached to the element.

## Pipes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ export class LoadClickDirective extends RxDestroy implements OnInit {
@Input()
loadClickClass: string;

@Input()
disableAttribute = true;

ngOnInit() {
this._renderer.listen(
this._el.nativeElement,
Expand All @@ -52,11 +55,23 @@ export class LoadClickDirective extends RxDestroy implements OnInit {

this._renderer.addClass(this._el.nativeElement, defaultClass);

if (this.disableAttribute) {
this._renderer.setAttribute(
this._el.nativeElement,
'disabled',
''
);
}

this.jpLoadClick()
.pipe(
finalize(() =>
this._renderer.removeClass(this._el.nativeElement, defaultClass)
),
finalize(() => {
this._renderer.removeClass(this._el.nativeElement, defaultClass);

if (this.disableAttribute) {
this._renderer.removeAttribute(this._el.nativeElement, 'disabled');
}
}),
takeUntil(this.destroyed$)
)
.subscribe();
Expand Down

0 comments on commit 49f5b6f

Please sign in to comment.