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

fix(core:button): disabled/loading state #6183

Merged

Conversation

coryrylan
Copy link
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • If applicable, have a visual design approval

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • clarity.design website / infrastructure changes
  • Other... Please describe:

What is the current behavior?

If a button was disabled prior to the loading state change it would attempt to revert to inital disabled state once loading was back to default. However the logic was not quite right and would break the loading state in subsequent updates.

Issue Number: #6129

What is the new behavior?

Now the loading state will disable the button when not default and when switch back to default set the disabled property the original value properly.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@coryrylan coryrylan self-assigned this Jul 26, 2021

.button-spinner {
--ring-color: #{$cds-global-color-construction-400};
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was able to use the component properties and simplify the CSS

await componentIsStable(anchorButton);
expect(anchor.querySelector('cds-button').readonly).toBe(true);
});
describe('Button link', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this describe since it was nested in the describe above which made it a bit confusing what component it was referencing.

${this.loadingState === ClrLoadingState.loading
? html`<cds-progress-circle .size=${this.size === 'sm' ? '12' : '18'} status="info"></cds-progress-circle>`
: ''}
${this.loadingState === ClrLoadingState.default ? html`<slot></slot>` : ''}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout was simplified and didn't need the wrapper elements anymore

</div>
`;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Icon button was the same template/logic duplicated as the inherited template

import { errorStandardIcon } from '@cds/core/icon/shapes/error-standard.js';
import { checkIcon } from '@cds/core/icon/shapes/check.js';

ClarityIcons.addIcons(errorStandardIcon, checkIcon);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving the side effects to the register to follow the rest of the component register files

- update to initial disabled state after loading state has updated

Signed-off-by: Cory Rylan <splintercode.cb@gmail.com>
@coryrylan coryrylan force-pushed the topic/core-loading-state-fix branch from 5058c08 to e827550 Compare July 26, 2021 17:31
it('should set spinner size to "12" if size "sm"', () => {
const templateResult = iconSpinner('sm');
expect(templateResult.values.indexOf('12') > -1).toBe(true);
});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to the rest of the loading state specs

set loadingState(value: keyof typeof ClrLoadingState) {
// track prior disabled state to set prior value after button is re-enabled from a loading state
if (this._loadingState === ClrLoadingState.default) {
this._disabled = this.disabled;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The _disabled property was the key fix. To preserve the disabled state while not breaking or causing side effects we need to grab what the current disabled state is when updating from default to something else. This way when we go back to default we can use what the prior disabled state was.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants