An open source design system that's fully customizable and agent ready
TypeScript
fix(Button): correct loading and disabled interaction states (#5627)
rubyycheungf0dc6b44f767
diff --git a/.changeset/button-loading-disabled-states.md b/.changeset/button-loading-disabled-states.mdnew file mode 100644index 0000000000..67743888c5--- /dev/null+++ b/.changeset/button-loading-disabled-states.md@@ -0,0 +1,8 @@+---+'@astryxdesign/core': patch+---++[fix] Keep loading-button spinners at full contrast while interaction is+blocked, and suppress pressed feedback for disabled and loading buttons.++@rubyycheungdiff --git a/packages/core/src/Button/Button.test.tsx b/packages/core/src/Button/Button.test.tsxindex d8914f04d1..0618b3875c 100644--- a/packages/core/src/Button/Button.test.tsx+++ b/packages/core/src/Button/Button.test.tsx@@ -70,6 +70,16 @@ describe('Button', () => {const button = screen.getByRole('button');// Button should be disabled when loadingexpect(button).toBeDisabled();+ expect(button.className).toContain('styles.inactive');+ expect(button.className).not.toContain('styles.disabled');+ });++ it('keeps the dimmed treatment for explicitly disabled buttons', () => {+ render(<Button label="Submit" isDisabled />);+ const button = screen.getByRole('button');+ expect(button).toBeDisabled();+ expect(button.className).toContain('styles.inactive');+ expect(button.className).toContain('styles.disabled');});it('sets aria-busy synchronously while clickAction is pending', async () => {diff --git a/packages/core/src/Button/Button.tsx b/packages/core/src/Button/Button.tsxindex f982254829..c9c15fe57c 100644--- a/packages/core/src/Button/Button.tsx+++ b/packages/core/src/Button/Button.tsx@@ -99,18 +99,20 @@ const styles = stylex.create({pressable: {transform: {default: 'scale(1)',- ':active': 'scale(0.98)',+ ':active:where(:not(:disabled,[aria-disabled="true"]))': 'scale(0.98)',},},- disabled: {+ inactive: {cursor: 'default',- opacity: 0.5,backgroundImage: 'none',transform: {default: 'none',':active': 'none',},},+ disabled: {+ opacity: 0.5,+ },ariaDisabled: {// The variants' hover treatment already steps aside for// `[aria-disabled]`; `:active` still matches a press on an aria-disabled@@ -270,7 +272,8 @@ export interface ButtonProps extends BaseProps<HTMLButtonElement> {*/isDisabled?: boolean;/**- * Whether the button is in a loading state.+ * Whether the button is in a loading state. Loading prevents interaction+ * without dimming the spinner; explicit disabled states remain dimmed.* @default false*/isLoading?: boolean;@@ -573,6 +576,10 @@ export function Button({// not disabled, so clicks keep landing and can interrupt the in-flight action.const buttonDisabled =isDisabled || groupDisabled || (isLoadingState && !isInterruptible);+ // A loading button remains non-interactive, but its spinner communicates an+ // active state and must retain contrast. Only explicitly disabled controls+ // receive the visually dimmed treatment.+ const visuallyDisabled = isDisabled || groupDisabled;// isIconOnly prop is the source of truth for icon-only rendering.// When false (default), label is always rendered as visible text.@@ -639,7 +646,8 @@ export function Button({sizeStyles[size],isIconOnly && styles.iconOnly,interactionOverlayStyles.backgroundImage,- buttonDisabled && styles.disabled,+ buttonDisabled && styles.inactive,+ visuallyDisabled && styles.disabled,useAriaDisabled && styles.ariaDisabled,renderAsLink && styles.link,!buttonGroup && styles.pressable,