Skip to content

Commit 5ed497a

Browse files
hchevalliergcornut
authored andcommitted
feat(button): add disabled behavior with aria-disabled only
1 parent 4e2214c commit 5ed497a

File tree

6 files changed

+22
-4
lines changed

6 files changed

+22
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Changed
11+
12+
- `Button`: add disabled behavior with `aria-disabled` only
13+
1014
## [3.14.0][] - 2025-05-13
1115

1216
### Fixed

packages/lumx-core/src/scss/components/button/_mixins.scss

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@
132132
}
133133
}
134134

135-
&:hover,
135+
&:hover:not([aria-disabled="true"]),
136136
&[class*="--is-hovered"] {
137137
@if $color == "primary" and $emphasis == lumx-base-const("emphasis", "HIGH") {
138138
color: var(--lumx-button-#{$emphasis}-state-hover-#{$theme}-color);
@@ -158,7 +158,7 @@
158158
}
159159
}
160160

161-
&:active,
161+
&:active:not([aria-disabled="true"]),
162162
&[class*="--is-active"] {
163163
@if $color == "primary" and $emphasis == lumx-base-const("emphasis", "HIGH") {
164164
color: var(--lumx-button-#{$emphasis}-state-active-#{$theme}-color);
@@ -192,6 +192,9 @@
192192
&:disabled,
193193
&[aria-disabled="true"] {
194194
@include lumx-state-disabled-input;
195+
// Enabling pointer-events to display label tooltips on hover
196+
// @TODO: should be moved in the mixin when all disabled states will be aligned
197+
pointer-events: all;
195198
}
196199
}
197200

packages/lumx-core/src/scss/core/state/_mixins.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@
133133
@mixin lumx-state-disabled-input() {
134134
pointer-events: none;
135135
opacity: 0.5;
136+
cursor: default;
136137
}
137138

138139
@mixin lumx-state($state, $emphasis, $color, $theme: null) {

packages/lumx-react/src/components/button/Button.stories.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ export const StateVariations = {
178178
Active: { isActive: true },
179179
Focused: { isFocused: true },
180180
Disabled: { isDisabled: true },
181+
AriaDisabled: { 'aria-disabled': true },
181182
},
182183
// Emphasis/Background
183184
sections: {
@@ -212,6 +213,7 @@ export const Theming = {
212213
Active: { isActive: true },
213214
Focused: { isFocused: true },
214215
Disabled: { isDisabled: true },
216+
AriaDisabled: { 'aria-disabled': true },
215217
},
216218
rows: {
217219
Default: {},

packages/lumx-react/src/components/button/Button.test.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ describe(`<${Button.displayName}>`, () => {
6363
expect(buttonWrapper).toBeInTheDocument();
6464
expect(button).toBe(within(buttonWrapper as any).queryByRole('button', { name: label }));
6565
});
66+
67+
it('should prevent click when aria-disabled', () => {
68+
const onClick = jest.fn();
69+
const { button } = setup({ children: 'Label', 'aria-disabled': true, onClick });
70+
expect(button.onclick).toBeFalsy();
71+
});
6672
});
6773

6874
// Common tests suite.

packages/lumx-react/src/components/button/ButtonRoot.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export type ButtonSize = Extract<Size, 's' | 'm'>;
2020

2121
export interface BaseButtonProps
2222
extends GenericProps,
23-
Pick<AriaAttributes, 'aria-expanded' | 'aria-haspopup' | 'aria-pressed' | 'aria-label'>,
23+
Pick<AriaAttributes, 'aria-expanded' | 'aria-haspopup' | 'aria-pressed' | 'aria-label' | 'aria-disabled'>,
2424
HasTheme {
2525
/** Color variant. */
2626
color?: ColorPalette;
@@ -106,6 +106,7 @@ export const ButtonRoot = forwardRef<ButtonRootProps, HTMLButtonElement | HTMLAn
106106
hasBackground,
107107
href,
108108
isDisabled = disabled,
109+
'aria-disabled': ariaDisabled = isDisabled,
109110
isSelected,
110111
isActive,
111112
isFocused,
@@ -172,8 +173,9 @@ export const ButtonRoot = forwardRef<ButtonRootProps, HTMLButtonElement | HTMLAn
172173
return (
173174
<button
174175
{...forwardedProps}
176+
{...(ariaDisabled ? { onClick: undefined } : undefined)}
175177
disabled={isDisabled}
176-
aria-disabled={isDisabled}
178+
aria-disabled={ariaDisabled}
177179
aria-label={ariaLabel}
178180
ref={ref as RefObject<HTMLButtonElement>}
179181
className={buttonClassName}

0 commit comments

Comments
 (0)