Skip to content

Commit 01b1051

Browse files
WioletaKolodziejSidnioulz
authored andcommitted
fix(a11y): replace native disabled with isDisabled and aria-disabled in Button.
1 parent 546aece commit 01b1051

6 files changed

Lines changed: 39 additions & 12 deletions

File tree

code/addons/onboarding/src/features/IntentSurvey/IntentSurvey.stories.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,23 @@ export const Default: Story = {};
2121
export const Submitting: Story = {
2222
play: async ({ args }) => {
2323
const button = await screen.findByRole('button', { name: 'Submit' });
24-
await expect(button).toBeDisabled();
24+
await expect(button).toHaveAttribute('aria-disabled', 'true');
2525

2626
await userEvent.click(await screen.findByText('Design system'));
27-
await expect(button).toBeDisabled();
27+
await expect(button).toHaveAttribute('aria-disabled', 'true');
2828

2929
await userEvent.click(await screen.findByText('Functional testing'));
3030
await userEvent.click(await screen.findByText('Accessibility testing'));
3131
await userEvent.click(await screen.findByText('Visual testing'));
32-
await expect(button).toBeDisabled();
32+
await expect(button).toHaveAttribute('aria-disabled', 'true');
3333

3434
await userEvent.selectOptions(screen.getByRole('combobox'), ['We use it at work']);
35-
await expect(button).not.toBeDisabled();
35+
await expect(button).not.toHaveAttribute('aria-disabled', 'true');
3636

3737
await userEvent.click(button);
3838

3939
await waitFor(async () => {
40-
await expect(button).toBeDisabled();
40+
await expect(button).toHaveAttribute('aria-disabled', 'true');
4141
await expect(args.onComplete).toHaveBeenCalledWith({
4242
building: {
4343
'application-ui': false,

code/core/src/components/components/Button/Button.stories.tsx

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { fn } from 'storybook/test';
66
import { styled } from 'storybook/theming';
77

88
import preview from '../../../../../.storybook/preview';
9-
import { Button } from './Button';
9+
import { Button, type ButtonProps } from './Button';
1010

1111
const meta = preview.meta({
1212
id: 'button-component',
@@ -291,6 +291,32 @@ export const Disabled = meta.story({
291291
ariaLabel: false,
292292
disabled: true,
293293
children: 'Disabled Button',
294+
onClick: fn(),
295+
},
296+
render: (args) => (
297+
<Row>
298+
<Button variant="solid" {...args}>
299+
Disabled Button
300+
</Button>
301+
</Row>
302+
),
303+
play: async ({ args, canvas, step }) => {
304+
const button = canvas.getByRole('button', { name: 'Disabled Button' });
305+
306+
await step('Disabled button should be aria-disabled', async () => {
307+
expect(button).toHaveAttribute('aria-disabled', 'true');
308+
});
309+
310+
await step('Disabled button should not be clickable', async () => {
311+
button.click();
312+
expect(args.onClick).not.toHaveBeenCalled();
313+
});
314+
315+
await step('Disabled button should be focusable for accessibility', async () => {
316+
const button = canvas.getByRole('button', { name: 'Disabled Button' });
317+
button.focus();
318+
expect(button).toHaveFocus();
319+
});
294320
},
295321
});
296322

code/core/src/components/components/Button/Button.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,12 @@ export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
138138
variant={variant}
139139
size={size}
140140
padding={padding}
141-
disabled={disabled || readOnly}
141+
aria-disabled={disabled || readOnly ? 'true' : undefined}
142142
readOnly={readOnly}
143143
active={active}
144144
animating={isAnimating}
145145
animation={animation}
146-
onClick={handleClick}
146+
onClick={disabled || readOnly ? undefined : handleClick}
147147
aria-label={!readOnly && ariaLabel !== false ? ariaLabel : undefined}
148148
aria-keyshortcuts={readOnly ? undefined : shortcutAttribute}
149149
{...(readOnly ? {} : ariaDescriptionAttrs)}

code/e2e-tests/addon-toolbars.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ test.describe('addon-toolbars', () => {
3131
await sbPage.navigateToStory('core/toolbars/globals', 'override-locale');
3232
await expect(sbPage.previewRoot()).toContainText('안녕하세요');
3333

34-
const button = sbPage.page.getByLabel('Internationalization locale');
35-
await expect(button).toBeDisabled();
34+
const button = sbPage.page.getByTitle('Internationalization locale');
35+
await expect(button).toHaveAttribute('aria-disabled', 'true');
3636
});
3737
});

code/e2e-tests/addon-viewport.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,6 @@ test.describe('addon-viewport', () => {
5454

5555
const toolbar = page.getByLabel('Viewport size');
5656

57-
await expect(toolbar).toBeDisabled();
57+
await expect(toolbar).toHaveAttribute('aria-disabled', 'true');
5858
});
5959
});

test-storybooks/portable-stories-kitchen-sink/react/e2e-tests/component-testing.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,8 @@ test.describe("component testing", () => {
238238

239239
await runTestsButton.click();
240240

241-
await expect(watchModeButton).toBeDisabled();
241+
// The test button will be disabled as tests are running
242+
expect(watchModeButton).toHaveAttribute("aria-disabled", "true"),
242243

243244
// Wait for test results to appear
244245
await expect(page.locator("#testing-module-description")).toHaveText(

0 commit comments

Comments
 (0)