Skip to content

Commit

Permalink
fix(button): buttons starting w loading-state should be come enabled …
Browse files Browse the repository at this point in the history
…after

- current logic will put a button back to enabled when switching default -> loading/error -> default, but not if the button starts in a loadingState other than default

fixes #172
  • Loading branch information
Ashley Ryan authored and ashleyryan committed Sep 28, 2022
1 parent 52922e1 commit fed0d13
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
22 changes: 22 additions & 0 deletions projects/core/src/button/button.element.spec.ts
Expand Up @@ -279,6 +279,28 @@ describe('button element', () => {
expect(component.disabled).not.toBeTruthy();
});

it('should go back to enabled when loadingState changes back to default, starting non default', async () => {
console.log('my test');
const testElement2 = await createTestElement(html`
<cds-button loading-state="loading">
<span>${placeholderText}</span>
</cds-button>
`);

const component2 = testElement2.querySelector<CdsButton>('cds-button');

await componentIsStable(component2);
expect(component2.disabled).toBeTruthy();

component2.loadingState = ClrLoadingState.success;
await componentIsStable(component2);
expect(component2.disabled).toBeTruthy();

component2.loadingState = ClrLoadingState.default;
await componentIsStable(component2);
expect(component2.disabled).not.toBeTruthy();
});

it('should stay disabled when loadingState changes back to default', async () => {
await componentIsStable(component);
component.disabled = true;
Expand Down
5 changes: 3 additions & 2 deletions projects/core/src/button/button.element.ts
Expand Up @@ -97,7 +97,7 @@ export class CdsButton extends CdsBaseButton {
super.firstUpdated(props);

if (!this.isDefaultLoadingState(this.loadingState)) {
this.disabled = true;
super.disabled = true;
}
}

Expand Down Expand Up @@ -144,7 +144,8 @@ export class CdsButton extends CdsBaseButton {
super.disabled = this._disabledExternally;
}

// when the loading state changes, the disabled state should be set to what the consumer manually set, if set
// when the loading state changes,
// the disabled state should be set back to what the consumer manually set (if they set it)
// the setter here should never be called in the component, call super instead
// https://github.com/vmware-clarity/core/issues/129
private _disabledExternally = false;
Expand Down

0 comments on commit fed0d13

Please sign in to comment.