Skip to content
This repository has been archived by the owner on Mar 27, 2023. It is now read-only.

Commit

Permalink
[NG] fix to allow loading binding to be falsy values
Browse files Browse the repository at this point in the history
The recent refactoring of loading buttons allows strict true/false values, but previously it also supported falsy values. This reenables that functionality for backwards compatibility.

closes #2355

Signed-off-by: Jeremy Wilken <[email protected]>
  • Loading branch information
gnomeontherun committed Jun 14, 2018
1 parent 39537e4 commit f88b418
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
12 changes: 12 additions & 0 deletions src/clr-angular/utils/loading/loading.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ describe('Loading directive', function() {
expect(this.listener.loadingStateChange).toHaveBeenCalledTimes(1);
});

it('handles null or other falsy values as false', function() {
this.testComponent.loading = null;
this.fixture.detectChanges();
expect(this.clarityDirective.loadingState).toEqual(ClrLoadingState.DEFAULT);
this.testComponent.loading = undefined;
this.fixture.detectChanges();
expect(this.clarityDirective.loadingState).toEqual(ClrLoadingState.DEFAULT);
this.testComponent.loading = 0;
this.fixture.detectChanges();
expect(this.clarityDirective.loadingState).toEqual(ClrLoadingState.DEFAULT);
});

it('stops loading when destroyed', function() {
this.testComponent.loading = true;
this.fixture.detectChanges();
Expand Down
12 changes: 3 additions & 9 deletions src/clr-angular/utils/loading/loading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,12 @@ export class ClrLoading implements OnDestroy {

@Input('clrLoading')
public set loadingState(value: boolean | ClrLoadingState) {
if (value === null) {
if (value === true) {
value = ClrLoadingState.LOADING;
} else if (!value) {
value = ClrLoadingState.DEFAULT;
}

if (typeof value === 'boolean') {
if (value) {
value = ClrLoadingState.LOADING;
} else {
value = ClrLoadingState.DEFAULT;
}
}

if (value === this._loadingState) {
return;
}
Expand Down
1 change: 1 addition & 0 deletions src/dev/src/app/buttons/button-loading.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ <h4>Loading Buttons</h4>
<h4>Small Loading Buttons</h4>
<button [clrLoading]="validateSmState" class="btn btn-sm btn-info-outline" (click)="validateSmDemo()">Validate</button>
<button [clrLoading]="submitSmState" type="submit" class="btn btn-sm btn-success-outline" (click)="submitSmDemo()">Submit</button>
<button [clrLoading]="validateFalsyState" class="btn btn-sm btn-info-outline" (click)="validateFalsyDemo()">Validate</button>
8 changes: 8 additions & 0 deletions src/dev/src/app/buttons/button-loading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export class ButtonLoadingDemo {
public submitState: ClrLoadingState = ClrLoadingState.DEFAULT;
public validateSmState: boolean = false;
public submitSmState: ClrLoadingState = ClrLoadingState.DEFAULT;
public validateFalsyState: any;

validateDemo() {
this.validateState = ClrLoadingState.LOADING;
Expand Down Expand Up @@ -44,4 +45,11 @@ export class ButtonLoadingDemo {
this.submitSmState = ClrLoadingState.DEFAULT;
}, 1500);
}

validateFalsyDemo() {
this.validateFalsyState = true;
setTimeout(() => {
this.validateFalsyState = null;
}, 1500);
}
}

0 comments on commit f88b418

Please sign in to comment.