Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(core): make disabled Button focusable via aria-disabled per AST-085 (#7906)

Geervan4e6e67df655f
diff --git a/.changeset/button-focusable-disabled.md b/.changeset/button-focusable-disabled.md
new file mode 100644
index 0000000000..fd134caa00
--- /dev/null
+++ b/.changeset/button-focusable-disabled.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] Button: disabled buttons no longer render the native `disabled` attribute. They stay focusable in keyboard tab order, keep focus when they become disabled while focused (a link Button, which becomes a `<button>` when disabled, still moves focus), and expose `aria-disabled="true"`. All activation paths (mouse clicks, Enter, Space) and clickAction/onClick callbacks remain blocked without losing focus to the document body. A disabled named submit Button withholds its name so `new FormData(form, submitter)` omits its value (FR3). A ButtonGroup whose members are all disabled (whether on the group or individually) keeps its one Tab stop instead of dropping out of the Tab order or giving every member its own stop, and Carousel's hidden scroll buttons are never Tab stops. This meets AST-085 FR1–FR3, FR6 and FR7, and FR4 for every Button that is not a link. Tests that assert `toBeDisabled()` or `:disabled` should query `[aria-disabled="true"]` instead.
+
+@Geervan
diff --git a/apps/storybook/stories/BottomSheet.stories.tsx b/apps/storybook/stories/BottomSheet.stories.tsx
index 4c090f4ef0..d0b1f0af56 100644
--- a/apps/storybook/stories/BottomSheet.stories.tsx
+++ b/apps/storybook/stories/BottomSheet.stories.tsx
@@ -1038,7 +1038,8 @@ export const ExitFocusControlRemoved: Story = {
/**
* Browser fixture: Done closes the sheet, and 100 ms into the exit the Done
- * control is disabled. The sheet goes inert and hidden as focus leaves it.
+ * control is disabled. Focus stays on Done and returns to "Open sheet" when
+ * the sheet closes (FR9).
*/
export const ExitFocusControlDisabled: Story = {
tags: ['!autodocs'],
diff --git a/packages/core/src/BottomSheet/__tests__/BottomSheetExitFocus.a11y.browser.spec.ts b/packages/core/src/BottomSheet/__tests__/BottomSheetExitFocus.a11y.browser.spec.ts
index f947e5d724..ddcd7bf097 100644
--- a/packages/core/src/BottomSheet/__tests__/BottomSheetExitFocus.a11y.browser.spec.ts
+++ b/packages/core/src/BottomSheet/__tests__/BottomSheetExitFocus.a11y.browser.spec.ts
@@ -7,11 +7,11 @@
* closes the sheet, and during the exit the Done control is removed or
* disabled.
* @output Real-engine proof that a closing sheet that held focus goes inert
- * and aria-hidden as soon as that focus drops to the page, while its exit
- * still runs.
- * @position Chromium and WebKit; the disabled case runs in Chromium only. The
- * removed case needs a real engine: React drops Chromium's focusout for an
- * element it removes, and WebKit sends none.
+ * and aria-hidden as soon as that focus drops to the page (removed case);
+ * when the control is disabled, focus stays on Done during the exit and
+ * returns to Open sheet when the sheet closes (FR9).
+ * @position Chromium and WebKit. The removed case needs a real engine: React
+ * drops Chromium's focusout for an element it removes, and WebKit sends none.
*/
import {expect, test, type Page} from '@astryxdesign/a11y-spec/playwright';
@@ -89,18 +89,37 @@ async function sawInertExit(page: Page, story: string): Promise<boolean> {
return result;
}
-for (const [story, change] of [
- ['exit-focus-control-removed', 'removed'],
- ['exit-focus-control-disabled', 'disabled'],
-] as const) {
- test(`goes inert once its focused control is ${change} during the exit`, async ({
- page,
- browserName,
- }) => {
- test.skip(
- change === 'disabled' && browserName !== 'chromium',
- 'Where focus goes from a disabled control is engine-specific; Chromium moves it to the page.',
- );
- expect(await sawInertExit(page, story)).toBe(true);
- });
-}
+test('goes inert once its focused control is removed during the exit', async ({
+ page,
+}) => {
+ expect(await sawInertExit(page, 'exit-focus-control-removed')).toBe(true);
+});
+
+test('keeps focus on Done when disabled during the exit and returns to Open sheet when closed', async ({
+ page,
+}) => {
+ await page.goto(
+ `${storybook.origin}/iframe.html?id=core-bottomsheet--exit-focus-control-disabled&viewMode=story`,
+ );
+ const opener = page.getByRole('button', {name: 'Open sheet', exact: true});
+ await opener.focus();
+ await page.keyboard.press('Enter');
+ const done = page.getByRole('button', {name: 'Done', exact: true});
+ await expect(done).toBeVisible();
+ const dialog = page.locator('dialog[aria-label="Exit focus"]');
+ await expect
+ .poll(async () =>
+ dialog.evaluate(node => node.getAnimations({subtree: true}).length),
+ )
+ .toBe(0);
+ await done.focus();
+ await page.keyboard.press('Enter');
+
+ // Done becomes disabled during the exit motion; focus stays on Done (FR9).
+ await expect(done).toHaveAttribute('aria-disabled', 'true');
+ await expect(done).toBeFocused();
+
+ // Once the exit ends, the dialog closes and focus returns to the opener.
+ await expect(dialog).toBeHidden();
+ await expect(opener).toBeFocused();
+});
diff --git a/packages/core/src/Button/Button.doc.mjs b/packages/core/src/Button/Button.doc.mjs
index e4659769fb..bc37f27345 100644
--- a/packages/core/src/Button/Button.doc.mjs
+++ b/packages/core/src/Button/Button.doc.mjs
@@ -151,7 +151,7 @@ export const docs = {
{
name: 'isDisabled',
type: 'boolean',
- description: 'Disables the button. When a tooltip is present, uses aria-disabled instead of native disabled so the button stays focusable.',
+ description: 'Disables the button. Uses aria-disabled instead of native disabled so the button stays focusable.',
default: 'false',
},
{
@@ -351,7 +351,7 @@ export const docsZh = {
{
name: 'isDisabled',
type: 'boolean',
- description: '禁用按钮。存在工具提示时,使用 aria-disabled 代替原生 disabled 以保持可聚焦。',
+ description: '禁用按钮。使用 aria-disabled 代替原生 disabled 以保持可聚焦。',
default: 'false',
},
{name: 'icon', type: 'ReactNode', description: '图标元素。未显式指定尺寸的 Astryx Icon 在 sm/md 按钮中默认为 sm,在 lg 按钮中默认为 md。仅提供 icon 而不提供 children 时,按钮渲染为正方形的纯图标按钮。'},
@@ -430,6 +430,6 @@ export const docsDense = {
tooltip: 'tooltip on hover',
onClick: 'standard click handler; fires before clickAction',
clickAction: 'async click handler; shows loading while promise pending',
- isDisabled: 'disables button; uses aria-disabled when tooltip present',
+ isDisabled: 'disables button; uses aria-disabled instead of native disabled',
},
};
diff --git a/packages/core/src/Button/Button.test.tsx b/packages/core/src/Button/Button.test.tsx
index 4eec0d7252..ac7dac70ea 100644
--- a/packages/core/src/Button/Button.test.tsx
+++ b/packages/core/src/Button/Button.test.tsx
@@ -148,7 +148,8 @@ describe('Button', () => {
it('keeps the dimmed treatment for explicitly disabled buttons', () => {
render(<Button label="Submit" isDisabled />);
const button = screen.getByRole('button');
- expect(button).toBeDisabled();
+ expect(button).not.toHaveAttribute('disabled');
+ expect(button).toHaveAttribute('aria-disabled', 'true');
expect(button.className).toContain('styles.inactive');
expect(button.className).toContain('styles.disabled');
});
@@ -494,6 +495,48 @@ describe('Button', () => {
expect(screen.getByRole('button')).toHaveAttribute('type', 'submit');
});
+ it('withholds name while disabled so FormData omits the submitter (spec:AST-085 FR3)', () => {
+ const {rerender} = render(
+ <form data-testid="form">
+ <Button label="Save" type="submit" name="intent" value="save" />
+ </form>,
+ );
+ const form = screen.getByTestId<HTMLFormElement>('form');
+ const enabledButton = screen.getByRole('button', {name: 'Save'});
+ expect(enabledButton).toHaveAttribute('name', 'intent');
+ expect(new FormData(form, enabledButton).get('intent')).toBe('save');
+
+ rerender(
+ <form data-testid="form">
+ <Button
+ label="Save"
+ type="submit"
+ name="intent"
+ value="save"
+ isDisabled
+ />
+ </form>,
+ );
+ const disabledButton = screen.getByRole('button', {name: 'Save'});
+ expect(disabledButton).not.toHaveAttribute('name');
+ expect(disabledButton).toHaveAttribute('aria-disabled', 'true');
+ expect(disabledButton).not.toHaveAttribute('disabled');
+ expect(new FormData(form, disabledButton).get('intent')).toBeNull();
+
+ rerender(
+ <form data-testid="form">
+ <ButtonGroup label="Actions" isDisabled>
+ <Button label="Save" type="submit" name="intent" value="save" />
+ </ButtonGroup>
+ </form>,
+ );
+ const groupDisabledButton = screen.getByRole('button', {name: 'Save'});
+ expect(groupDisabledButton).not.toHaveAttribute('name');
+ expect(groupDisabledButton).toHaveAttribute('aria-disabled', 'true');
+ expect(groupDisabledButton).not.toHaveAttribute('disabled');
+ expect(new FormData(form, groupDisabledButton).get('intent')).toBeNull();
+ });
+
describe('tooltip as description (FR12)', () => {
it('describes the button by a tooltip that adds to its name', () => {
render(<Button label="Save" tooltip="Save your changes" />);
@@ -722,21 +765,18 @@ describe('Button', () => {
expect(handleKeyDown).toHaveBeenCalledTimes(1);
});
- it('keeps native disabled (not aria-disabled) when isDisabled and not busy, even without a tooltip', () => {
+ it('uses aria-disabled (not native disabled) when isDisabled, even without a tooltip (AST-085)', () => {
render(<Button label="Save" isDisabled />);
const button = screen.getByRole('button');
- expect(button).toHaveAttribute('disabled');
- expect(button).not.toHaveAttribute('aria-disabled');
+ expect(button).not.toHaveAttribute('disabled');
+ expect(button).toHaveAttribute('aria-disabled', 'true');
});
- it('keeps native disabled when isDisabled and isLoading are both true (isDisabled wins)', () => {
+ it('uses aria-disabled (not native disabled) when isDisabled and isLoading are both true', () => {
render(<Button label="Save" isDisabled isLoading />);
const button = screen.getByRole('button');
- // "isDisabled behavior unchanged: that stays native disabled" — busy-only
- // aria-disabled is only for the case where busy is the SOLE reason the
- // button can't be clicked, not when it's also genuinely isDisabled.
- expect(button).toHaveAttribute('disabled');
- expect(button).not.toHaveAttribute('aria-disabled');
+ expect(button).not.toHaveAttribute('disabled');
+ expect(button).toHaveAttribute('aria-disabled', 'true');
});
it('has a live region that announces loading state', () => {
@@ -965,11 +1005,12 @@ describe('Button', () => {
expect(event.defaultPrevented).toBe(true);
});
- it('falls back to <button disabled> for a truly disabled href Button', () => {
+ it('falls back to <button> with aria-disabled for a disabled href Button', () => {
render(<Button label="Docs" href="https://example.com" isDisabled />);
expect(screen.queryByRole('link')).not.toBeInTheDocument();
const button = screen.getByRole('button', {name: 'Docs'});
- expect(button).toBeDisabled();
+ expect(button).not.toHaveAttribute('disabled');
+ expect(button).toHaveAttribute('aria-disabled', 'true');
});
});
diff --git a/packages/core/src/Button/Button.tsx b/packages/core/src/Button/Button.tsx
index d4d36e25d2..5a14feb06f 100644
--- a/packages/core/src/Button/Button.tsx
+++ b/packages/core/src/Button/Button.tsx
@@ -769,12 +769,6 @@ export function Button({
// (credit @AKnassa, #4879), which is exactly the bug this PR fixes.
const renderAsLink = href != null && !isTrueDisabled;
- // Use aria-disabled (button stays focusable) when busy-only, or when a
- // tooltip is present so keyboard users can still reach it. A genuinely
- // isDisabled/group-disabled button (not busy) keeps native disabled.
- const useAriaDisabled =
- buttonDisabled && (isBusyOnlyDisabled || tooltip != null);
-
// Attach tooltip behavior via the hook rather than wrapping the button in a
// <Tooltip> element. The hook adds hover/focus triggers to the button itself,
// so no extra DOM node is inserted — the button stays a direct child of its
@@ -790,15 +784,9 @@ export function Button({
// a re-click while pending starts a fresh action that interrupts the prior.
if (buttonDisabled || (actionInFlightRef.current && !isInterruptible)) {
e.preventDefault();
- // A native `disabled` element never dispatches a click at all, so it
- // never reaches a wrapping element's own handler either. An
- // aria-disabled button (busy-only, or with a tooltip) is still a real,
- // interactive element the DOM keeps dispatching clicks on —
- // preventDefault alone only cancels the button's OWN default action
- // (form submit, link navigation), not propagation. Without this, an
- // unavailable Button inside a clickable row/card/backdrop still
- // triggers that ancestor's action, which the previously native-disabled
- // control never did.
+ // An aria-disabled button still receives clicks. preventDefault cancels
+ // only its own default action, such as a form submit. Stop propagation
+ // so a clickable ancestor does not act.
e.stopPropagation();
return;
}
@@ -815,9 +803,9 @@ export function Button({
}
};
- // When aria-disabled, suppress activation keys (Enter/Space) but allow
- // other keys (Escape, arrows) to reach consumer handlers.
- const handleKeyDown = useAriaDisabled
+ // A disabled button cancels Enter and Space, its activation keys. Other
+ // keys, such as Escape and the arrows, still reach the caller's handler.
+ const handleKeyDown = buttonDisabled
? (e: React.KeyboardEvent<HTMLButtonElement>) => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
@@ -846,7 +834,7 @@ export function Button({
isGroupTracked && styles.trackedOverlay,
buttonDisabled && styles.inactive,
isTrueDisabled && styles.disabled,
- useAriaDisabled && styles.ariaDisabled,
+ buttonDisabled && styles.ariaDisabled,
renderAsLink && styles.link,
!buttonGroup &&
(isGroupTracked ? styles.pressableTracked : styles.pressable),
@@ -1004,7 +992,7 @@ export function Button({
// A caller's own busy or disabled state is kept, so a component that
// hands these props to a Button (a caller-rendered trigger) is heard.
aria-busy={isLoadingState || props['aria-busy'] || undefined}
- aria-disabled={useAriaDisabled || props['aria-disabled'] || undefined}
+ aria-disabled={buttonDisabled || props['aria-disabled'] || undefined}
onClick={handleClick}
{...(handleKeyDown ? {onKeyDown: handleKeyDown} : null)}>
{buttonContent}
@@ -1015,7 +1003,6 @@ export function Button({
<button
ref={mergedButtonRef}
type={type}
- disabled={useAriaDisabled ? undefined : buttonDisabled}
{...(inputGroup != null && buttonGroup == null
? inputGroupItemProps
: undefined)}
@@ -1023,13 +1010,14 @@ export function Button({
{...pressFeedback}
{...groupItemProps}
{...props}
+ {...(isTrueDisabled ? {name: undefined} : null)}
{...ariaLabelProp}
{...describedByProp}
{...edgeCompAttr}
// A caller's own busy or disabled state is kept, so a component that
// hands these props to a Button (a caller-rendered trigger) is heard.
aria-busy={isLoadingState || props['aria-busy'] || undefined}
- aria-disabled={useAriaDisabled || props['aria-disabled'] || undefined}
+ aria-disabled={buttonDisabled || props['aria-disabled'] || undefined}
onClick={handleClick}
{...(handleKeyDown ? {onKeyDown: handleKeyDown} : null)}>
{buttonContent}
diff --git a/packages/core/src/Button/__tests__/Button.a11y.states.ts b/packages/core/src/Button/__tests__/Button.a11y.states.ts
index eeebab9f18..5188ecdc84 100644
--- a/packages/core/src/Button/__tests__/Button.a11y.states.ts
+++ b/packages/core/src/Button/__tests__/Button.a11y.states.ts
@@ -159,8 +159,9 @@ export const BUTTON_BINDING_STATES = [
{
id: 'button-disabled',
binding: 'Button',
- summary: 'a hard-disabled button: unavailable, and out of the tab sequence',
- facts: facts({operable: false, focusable: false, unavailable: true}),
+ summary:
+ 'a hard-disabled button: unavailable, but still in the tab sequence (spec:AST-085 FR1)',
+ facts: facts({operable: false, unavailable: true}),
visibleLabel: 'Save changes',
storyId: 'a11y-button-pattern--button-disabled',
},
@@ -196,7 +197,7 @@ export const BUTTON_BINDING_STATES = [
id: 'icon-button-disabled',
binding: 'IconButton',
summary: 'a disabled icon button',
- facts: facts({operable: false, focusable: false, unavailable: true}),
+ facts: facts({operable: false, unavailable: true}),
visibleLabel: null,
storyId: 'a11y-button-pattern--icon-button-disabled',
},
@@ -264,7 +265,7 @@ export const BUTTON_BINDING_STATES = [
id: 'chat-send-disabled',
binding: 'ChatSendButton',
summary: 'the send control with nothing to send',
- facts: facts({operable: false, focusable: false, unavailable: true}),
+ facts: facts({operable: false, unavailable: true}),
visibleLabel: null,
storyId: 'a11y-button-pattern--chat-send-disabled',
},
diff --git a/packages/core/src/ButtonGroup/ButtonGroup.doc.mjs b/packages/core/src/ButtonGroup/ButtonGroup.doc.mjs
index 8979bda8ea..73ffa050bc 100644
--- a/packages/core/src/ButtonGroup/ButtonGroup.doc.mjs
+++ b/packages/core/src/ButtonGroup/ButtonGroup.doc.mjs
@@ -95,7 +95,7 @@ export const docs = {
{guidance: false, description: "Don't nest ButtonGroups. If you need multiple groups, place them side by side with a gap."},
{guidance: true, description: 'Name the group for what its buttons act on. The label is the group\'s accessible name and a screen reader reads it before each member.'},
{guidance: true, description: 'Keep the group a single Tab stop. Arrow keys move between members along the orientation, and Home/End jump to the ends. This is the WAI-ARIA APG roving tabindex technique: https://www.w3.org/WAI/ARIA/apg/practices/keyboard-interface/#kbd_roving_tabindex'},
- {guidance: false, description: "Don't disable the group to show that an action is in flight. A disabled member drops focus, so a keyboard user loses their place; leave the group enabled and show progress on the button that started the work."},
+ {guidance: false, description: "Don't disable the group to show that an action is in flight. Leave the group enabled and show progress on the button that started the work."},
],
anatomy: [
{name: 'Button', required: true, description: 'One or more Button or IconButton children that form the connected group.'},
@@ -136,7 +136,7 @@ export const docsZh = {
{guidance: false, description: '不要嵌套 ButtonGroup。如需多个组,请并排放置并留有间隔。'},
{guidance: true, description: '按钮组的标签应说明这些按钮作用于什么。该标签是按钮组的无障碍名称,屏幕阅读器会在每个成员之前朗读它。'},
{guidance: true, description: '按钮组是单个 Tab 停靠点。方向键沿排列方向在成员间移动焦点,Home/End 跳到首尾,禁用成员会被跳过——即 WAI-ARIA APG 的 roving tabindex 技术。'},
- {guidance: false, description: '不要用禁用整个按钮组来表示操作进行中。禁用的成员会失去焦点,键盘用户会丢失位置;请保持按钮组可用,并在发起操作的按钮上显示进度。'},
+ {guidance: false, description: '不要用禁用整个按钮组来表示操作进行中。请保持按钮组可用,并在发起操作的按钮上显示进度。'},
],
anatomy: [
{name: '按钮', required: true, description: '一个或多个 Button 或 IconButton 子元素,形成连接的组。'},
@@ -161,7 +161,7 @@ export const docsDense = {
{guidance: true, description: 'Label the group for what its buttons act on; it is the accessible name.'},
{guidance: true, description: 'Single Tab stop; arrows move between members, Home/End to ends (APG roving tabindex).'},
{guidance: true, description: 'Under the touch presentation a press tracks like a menu: slide across, the lifted button runs, a lift outside runs nothing. A mouse press acts as a native button\'s. Finger targets grow toward 44 px, up to half the gap to a neighbour; a menu trigger keeps its own opening.'},
- {guidance: false, description: "Don't disable the group for an in-flight action; a disabled member drops focus."},
+ {guidance: false, description: "Don't disable the group for an in-flight action; show progress on the active button instead."},
],
},
components: [
diff --git a/packages/core/src/ButtonGroup/ButtonGroup.test.tsx b/packages/core/src/ButtonGroup/ButtonGroup.test.tsx
index b1a160c840..83c95f8f3e 100644
--- a/packages/core/src/ButtonGroup/ButtonGroup.test.tsx
+++ b/packages/core/src/ButtonGroup/ButtonGroup.test.tsx
@@ -164,8 +164,14 @@ describe('ButtonGroup', () => {
);
expect(screen.getByRole('group')).toHaveAttribute('aria-disabled', 'true');
- expect(screen.getByRole('button', {name: 'Copy'})).toBeDisabled();
- expect(screen.getByRole('button', {name: 'Cut'})).toBeDisabled();
+ expect(screen.getByRole('button', {name: 'Copy'})).toHaveAttribute(
+ 'aria-disabled',
+ 'true',
+ );
+ expect(screen.getByRole('button', {name: 'Cut'})).toHaveAttribute(
+ 'aria-disabled',
+ 'true',
+ );
});
it('does not set aria-disabled when not disabled', () => {
@@ -977,7 +983,9 @@ describe('ButtonGroup', () => {
expect(screen.getByRole('button', {name: 'after'})).toHaveFocus();
});
- it('contributes no tab stop when the whole group is disabled', async () => {
+ it('keeps its one tab stop when the whole group is disabled', async () => {
+ // A group disabled as a whole keeps the focus order it has when
+ // enabled, so it still contributes exactly one tab stop.
const user = userEvent.setup();
render(
bracketed(
@@ -991,6 +999,36 @@ describe('ButtonGroup', () => {
await user.tab();
expect(screen.getByRole('button', {name: 'before'})).toHaveFocus();
+ await user.tab();
+ const copy = screen.getByRole('button', {name: 'Copy'});
+ expect(copy).toHaveFocus();
+ expect(copy).toHaveAttribute('aria-disabled', 'true');
+
+ await user.tab();
+ expect(screen.getByRole('button', {name: 'after'})).toHaveFocus();
+ });
+
+ it('keeps its one tab stop when every member is individually disabled', async () => {
+ // component:ButtonGroup FR8: an enabled group whose members are all
+ // isDisabled keeps its one tab stop.
+ const user = userEvent.setup();
+ render(
+ bracketed(
+ <ButtonGroup label="History">
+ <Button label="Undo" isDisabled />
+ <Button label="Redo" isDisabled />
+ </ButtonGroup>,
+ ),
+ );
+
+ await user.tab();
+ expect(screen.getByRole('button', {name: 'before'})).toHaveFocus();
+
+ await user.tab();
+ const undo = screen.getByRole('button', {name: 'Undo'});
+ expect(undo).toHaveFocus();
+ expect(undo).toHaveAttribute('aria-disabled', 'true');
+
await user.tab();
expect(screen.getByRole('button', {name: 'after'})).toHaveFocus();
});
diff --git a/packages/core/src/ButtonGroup/ButtonGroup.tsx b/packages/core/src/ButtonGroup/ButtonGroup.tsx
index f59cf8f3fe..deff3b9399 100644
--- a/packages/core/src/ButtonGroup/ButtonGroup.tsx
+++ b/packages/core/src/ButtonGroup/ButtonGroup.tsx
@@ -28,7 +28,7 @@ import type {ButtonSize} from '../Button';
import {radiusVars, shadowVars} from '../theme/tokens.stylex';
import type {Elevation} from '../utils/types';
import {SizeProvider, useSize} from '../SizeContext/SizeContext';
-import {useListFocus} from '../hooks/useListFocus';
+import {oneTabStopAmong, useInternalListFocus} from '../hooks/useListFocus';
import {PressGroupContext} from '../hooks/pressGroupContext';
import {
GROUP_PRESS_POINTERS,
@@ -137,6 +137,16 @@ const elevationStyles = stylex.create({
// Component
// =============================================================================
+// Roving rewrites `tabindex` on every item, so the selector cannot key off
+// a value: `[tabindex="0"]` would drop each member the moment it is stamped
+// -1. `a[href]` catches a Button rendered with `href`.
+const MEMBER_SELECTOR = 'button, a[href], [tabindex]';
+
+const keepDisabledGroupStop = oneTabStopAmong(
+ MEMBER_SELECTOR,
+ '[role="group"], [popover]',
+);
+
/**
* Groups buttons with connected styling — shared borders, proper border-radius
* handling (only on outer edges), and horizontal or vertical orientation.
@@ -189,21 +199,22 @@ export function ButtonGroup({
}: ButtonGroupProps): ReactNode {
const size = useSize(sizeProp, 'md');
- const {listRef, handleKeyDown, handleFocus} = useListFocus<HTMLDivElement>({
- // Roving rewrites `tabindex` on every item, so the selector cannot key off
- // a value: `[tabindex="0"]` would drop each member the moment it is
- // stamped -1. `a[href]` catches a Button rendered with `href`.
- itemSelector: 'button, a[href], [tabindex]',
- // A member's layer renders inline inside the group (useLayer does not
- // portal it), so a key pressed in an open DropdownMenu bubbles here. The
- // boundary is the group's own root or any layer, whichever is nearer to
- // the target. Naming the group's own root is what keeps a group rendered
- // inside a Popover or Toast working: bailing on any [popover] ancestor
- // instead would swallow every arrow key it owns.
- boundarySelector: '[role="group"], [popover]',
- orientation,
- hasRovingTabIndex: true,
- });
+ const {listRef, handleKeyDown, handleFocus} =
+ useInternalListFocus<HTMLDivElement>({
+ itemSelector: MEMBER_SELECTOR,
+ // A member's layer renders inline inside the group (useLayer does not
+ // portal it), so a key pressed in an open DropdownMenu bubbles here. The
+ // boundary is the group's own root or any layer, whichever is nearer to
+ // the target. Naming the group's own root is what keeps a group rendered
+ // inside a Popover or Toast working: bailing on any [popover] ancestor
+ // instead would swallow every arrow key it owns.
+ boundarySelector: '[role="group"], [popover]',
+ orientation,
+ hasRovingTabIndex: true,
+ // A group of disabled buttons keeps its one Tab stop, so a keyboard user
+ // still reaches it. Its members are focusable while disabled.
+ tabStopOrder: keepDisabledGroupStop,
+ });
const contextValue = useMemo(
() => ({orientation, isDisabled}),
diff --git a/packages/core/src/Calendar/Calendar.calendarSystems.test.tsx b/packages/core/src/Calendar/Calendar.calendarSystems.test.tsx
index 3dd7277465..703b65de4c 100644
--- a/packages/core/src/Calendar/Calendar.calendarSystems.test.tsx
+++ b/packages/core/src/Calendar/Calendar.calendarSystems.test.tsx
@@ -131,9 +131,13 @@ describe('Calendar in the Persian calendar', () => {
/>,
);
// min is the first day of Aban: no earlier day is in range.
- expect(screen.getByRole('button', {name: 'Previous month'})).toBeDisabled();
+ expect(
+ screen.getByRole('button', {name: 'Previous month'}),
+ ).toHaveAttribute('aria-disabled', 'true');
// max is the first day of Azar: a later day is in range.
- expect(screen.getByRole('button', {name: 'Next month'})).toBeEnabled();
+ expect(
+ screen.getByRole('button', {name: 'Next month'}),
+ ).not.toHaveAttribute('aria-disabled');
});
it('shows ISO 8601 week numbers', () => {
diff --git a/packages/core/src/Calendar/Calendar.test.tsx b/packages/core/src/Calendar/Calendar.test.tsx
index 458ce60712..c2013afbee 100644
--- a/packages/core/src/Calendar/Calendar.test.tsx
+++ b/packages/core/src/Calendar/Calendar.test.tsx
@@ -1434,7 +1434,10 @@ describe('Calendar', () => {
last.focus();
await user.keyboard('{ArrowRight}');
// January stays, focus stays on the max day.
- expect(screen.getByRole('button', {name: 'Next month'})).toBeDisabled();
+ expect(screen.getByRole('button', {name: 'Next month'})).toHaveAttribute(
+ 'aria-disabled',
+ 'true',
+ );
expect(document.activeElement).toBe(getDayButton(31));
// Later the range widens and the user clicks Next: no stale target
@@ -2084,14 +2087,14 @@ describe('Calendar', () => {
render(<Calendar focusDate="2026-01-01" min="2026-01-15" />);
const prevButton = getButton('Previous month');
- expect(prevButton).toBeDisabled();
+ expect(prevButton).toHaveAttribute('aria-disabled', 'true');
});
it('next button is disabled when focusDate month contains max', () => {
render(<Calendar focusDate="2026-01-01" max="2026-01-15" />);
const nextButton = getButton('Next month');
- expect(nextButton).toBeDisabled();
+ expect(nextButton).toHaveAttribute('aria-disabled', 'true');
});
it('outside days are not clickable when hasOutsideDays is true', async () => {
diff --git a/packages/core/src/Carousel/Carousel.test.tsx b/packages/core/src/Carousel/Carousel.test.tsx
index e794a21e4e..651581c8e2 100644
--- a/packages/core/src/Carousel/Carousel.test.tsx
+++ b/packages/core/src/Carousel/Carousel.test.tsx
@@ -268,8 +268,12 @@ describe('Carousel', () => {
const right = screen.getByLabelText('Scroll right');
expect(left).toBeInTheDocument();
expect(right).toBeInTheDocument();
- expect(left).toBeDisabled();
- expect(right).toBeDisabled();
+ expect(left).toHaveAttribute('aria-disabled', 'true');
+ expect(right).toHaveAttribute('aria-disabled', 'true');
+ // Disabled buttons stay focusable (spec:AST-085 FR1), so the hidden pill
+ // around each is inert: an invisible button is never a Tab stop.
+ expect(left.closest('[inert]')).not.toBeNull();
+ expect(right.closest('[inert]')).not.toBeNull();
});
describe('Shift + wheel horizontal scroll', () => {
@@ -485,8 +489,12 @@ describe('Carousel', () => {
// At the start edge: without loop the left button would be disabled.
makeOverflowing(scroller, 0);
- expect(screen.getByLabelText('Scroll left')).toBeEnabled();
- expect(screen.getByLabelText('Scroll right')).toBeEnabled();
+ expect(screen.getByLabelText('Scroll left')).not.toHaveAttribute(
+ 'aria-disabled',
+ );
+ expect(screen.getByLabelText('Scroll right')).not.toHaveAttribute(
+ 'aria-disabled',
+ );
});
it('wraps to the start when pressing next at the end', () => {
@@ -737,7 +745,7 @@ describe('Carousel', () => {
const next = screen.getByLabelText('Scroll right');
await user.click(next);
- expect(next).toBeDisabled();
+ expect(next).toHaveAttribute('aria-disabled', 'true');
expect(document.activeElement).toBe(getScroller());
expect(document.activeElement).not.toBe(document.body);
});
@@ -760,7 +768,7 @@ describe('Carousel', () => {
const previous = screen.getByLabelText('Scroll left');
await user.click(previous);
- expect(previous).toBeDisabled();
+ expect(previous).toHaveAttribute('aria-disabled', 'true');
expect(document.activeElement).toBe(getScroller());
});
@@ -804,7 +812,7 @@ describe('Carousel', () => {
const next = screen.getByLabelText('Scroll right');
await user.click(next);
- expect(next).toBeDisabled();
+ expect(next).toHaveAttribute('aria-disabled', 'true');
expect(document.activeElement).toBe(getScroller());
});
@@ -825,7 +833,7 @@ describe('Carousel', () => {
const next = screen.getByLabelText('Scroll right');
await user.click(next);
- expect(next).toBeDisabled();
+ expect(next).toHaveAttribute('aria-disabled', 'true');
expect(document.activeElement).toBe(getScroller());
});
@@ -850,8 +858,14 @@ describe('Carousel', () => {
await user.click(screen.getByLabelText('Scroll right'));
- expect(screen.getByLabelText('Scroll right')).toBeDisabled();
- expect(screen.getByLabelText('Scroll left')).toBeDisabled();
+ expect(screen.getByLabelText('Scroll right')).toHaveAttribute(
+ 'aria-disabled',
+ 'true',
+ );
+ expect(screen.getByLabelText('Scroll left')).toHaveAttribute(
+ 'aria-disabled',
+ 'true',
+ );
expect(document.activeElement).toBe(scroller);
expect(document.activeElement).not.toBe(document.body);
});
@@ -880,7 +894,10 @@ describe('Carousel', () => {
scroller.scrollLeft = 200;
fireEvent.scroll(scroller);
- expect(screen.getByLabelText('Scroll right')).toBeDisabled();
+ expect(screen.getByLabelText('Scroll right')).toHaveAttribute(
+ 'aria-disabled',
+ 'true',
+ );
expect(document.activeElement).toBe(document.body);
});
@@ -918,7 +935,7 @@ describe('Carousel', () => {
const next = screen.getByLabelText('Scroll right');
await user.click(next);
- expect(next).toBeEnabled();
+ expect(next).not.toHaveAttribute('aria-disabled');
expect(document.activeElement).toBe(next);
});
@@ -935,7 +952,7 @@ describe('Carousel', () => {
const next = screen.getByLabelText('Scroll right');
await user.click(next);
- expect(next).toBeEnabled();
+ expect(next).not.toHaveAttribute('aria-disabled');
expect(document.activeElement).toBe(next);
});
diff --git a/packages/core/src/Carousel/Carousel.tsx b/packages/core/src/Carousel/Carousel.tsx
index d42271fef9..51f7730641 100644
--- a/packages/core/src/Carousel/Carousel.tsx
+++ b/packages/core/src/Carousel/Carousel.tsx
@@ -781,6 +781,9 @@ export function Carousel({
layer.render(
<>
<div
+ // A hidden button is never a Tab stop or in the a11y tree. Its
+ // disabled state alone would keep it focusable.
+ inert={!canScrollStart || undefined}
{...stylex.props(
styles.buttonPill,
styles.buttonPillStart,
@@ -800,18 +803,18 @@ export function Carousel({
size="sm"
isIconOnly
// Disabled when there's nothing to scroll toward. Keeps the
- // button mounted (stable layout) but removes it from the tab
- // order and a11y tree while it's visually hidden, so keyboard
- // users don't land on an invisible control. The Effect above
- // hands focus to the scroll area when the state behind this
- // one flips it disabled.
+ // button mounted (stable layout). The Effect above hands focus
+ // to the scroll area when the state behind this one flips it
+ // disabled.
isDisabled={!canScrollStart}
onFocus={() => {
focusedNavRef.current = 'start';
}}
onBlur={event => {
// A disabled button was blurred by the commit, not the person.
- if (!event.currentTarget.disabled) {
+ if (
+ event.currentTarget.getAttribute('aria-disabled') !== 'true'
+ ) {
focusedNavRef.current = null;
}
}}
@@ -820,6 +823,9 @@ export function Carousel({
/>
</div>
<div
+ // A hidden button is never a Tab stop or in the a11y tree. Its
+ // disabled state alone would keep it focusable.
+ inert={!canScrollEnd || undefined}
{...stylex.props(
styles.buttonPill,
styles.buttonPillEnd,
@@ -839,14 +845,16 @@ export function Carousel({
size="sm"
isIconOnly
// See "Scroll left" — disabled while visually hidden so the
- // button stays mounted but out of the tab order / a11y tree.
+ // button stays mounted.
isDisabled={!canScrollEnd}
onFocus={() => {
focusedNavRef.current = 'end';
}}
onBlur={event => {
// A disabled button was blurred by the commit, not the person.
- if (!event.currentTarget.disabled) {
+ if (
+ event.currentTarget.getAttribute('aria-disabled') !== 'true'
+ ) {
focusedNavRef.current = null;
}
}}
diff --git a/packages/core/src/Carousel/__tests__/CarouselSnapPagingEdges.interaction.browser.spec.ts b/packages/core/src/Carousel/__tests__/CarouselSnapPagingEdges.interaction.browser.spec.ts
index 767872ff76..3ddaebb154 100644
--- a/packages/core/src/Carousel/__tests__/CarouselSnapPagingEdges.interaction.browser.spec.ts
+++ b/packages/core/src/Carousel/__tests__/CarouselSnapPagingEdges.interaction.browser.spec.ts
@@ -78,8 +78,12 @@ async function startSampling(
shown:
Math.abs(row.scrollLeft) - (lead == null ? 0 : translateX(lead)),
travel: row.scrollWidth - row.clientWidth,
- startDisabled: (startButton as HTMLButtonElement).disabled,
- endDisabled: (endButton as HTMLButtonElement).disabled,
+ startDisabled:
+ (startButton as HTMLButtonElement).getAttribute('aria-disabled') ===
+ 'true',
+ endDisabled:
+ (endButton as HTMLButtonElement).getAttribute('aria-disabled') ===
+ 'true',
held,
});
if (samples.length < 600) {
diff --git a/packages/core/src/Chat/ChatComposerInput.test.tsx b/packages/core/src/Chat/ChatComposerInput.test.tsx
index c0ff6c17fa..e5ce6ea7df 100644
--- a/packages/core/src/Chat/ChatComposerInput.test.tsx
+++ b/packages/core/src/Chat/ChatComposerInput.test.tsx
@@ -305,13 +305,16 @@ describe('ChatComposerInput', () => {
);
}
render(<Host />);
- expect(screen.getByRole('button', {name: 'Send'})).toBeDisabled();
+ expect(screen.getByRole('button', {name: 'Send'})).toHaveAttribute(
+ 'aria-disabled',
+ 'true',
+ );
screen.getByRole('textbox').focus();
act(() => {
handleRef.current!.insertToken({value: '@sam', label: 'Sam'});
});
const send = screen.getByRole('button', {name: 'Send'});
- expect(send).toBeEnabled();
+ expect(send).not.toHaveAttribute('aria-disabled');
fireEvent.click(send);
expect(onSubmit.mock.lastCall?.[0]).toContain('@sam');
});
diff --git a/packages/core/src/Chat/ChatDictationButton.test.tsx b/packages/core/src/Chat/ChatDictationButton.test.tsx
index 420d38c8e5..d46fbd3ed9 100644
--- a/packages/core/src/Chat/ChatDictationButton.test.tsx
+++ b/packages/core/src/Chat/ChatDictationButton.test.tsx
@@ -84,7 +84,7 @@ describe('ChatDictationButton', () => {
expect(
screen.getByRole('button', {name: 'Start dictation'}),
- ).toBeDisabled();
+ ).toHaveAttribute('aria-disabled', 'true');
});
it('forwards the root ref and accepted span props', () => {
diff --git a/packages/core/src/Chat/ChatSendButton.test.tsx b/packages/core/src/Chat/ChatSendButton.test.tsx
index c6b6757555..2b2abc8ad9 100644
--- a/packages/core/src/Chat/ChatSendButton.test.tsx
+++ b/packages/core/src/Chat/ChatSendButton.test.tsx
@@ -32,7 +32,10 @@ describe('ChatSendButton', () => {
it('is disabled with no composer context and no isDisabled prop', () => {
render(<ChatSendButton />);
- expect(screen.getByRole('button', {name: 'Send'})).toBeDisabled();
+ expect(screen.getByRole('button', {name: 'Send'})).toHaveAttribute(
+ 'aria-disabled',
+ 'true',
+ );
});
it('is enabled when isDisabled is explicitly false', () => {
@@ -294,7 +297,10 @@ describe('ChatSendButton', () => {
<ChatComposer onSubmit={onSubmit} value="" input={<div />} />,
);
// Empty composer — nothing to send.
- expect(screen.getByRole('button', {name: 'Send'})).toBeDisabled();
+ expect(screen.getByRole('button', {name: 'Send'})).toHaveAttribute(
+ 'aria-disabled',
+ 'true',
+ );
rerender(
<ChatComposer onSubmit={onSubmit} value="hello" input={<div />} />,
diff --git a/packages/core/src/DateInput/DateInputTouch.test.tsx b/packages/core/src/DateInput/DateInputTouch.test.tsx
index 344ae40d1b..6e3f7242c8 100644
--- a/packages/core/src/DateInput/DateInputTouch.test.tsx
+++ b/packages/core/src/DateInput/DateInputTouch.test.tsx
@@ -1035,7 +1035,7 @@ describe('DateInput — calendar surface', () => {
for (const name of ['Previous month', 'Next month']) {
// Still mounted, so the header cannot reflow...
expect(arrow(name)).toBeInTheDocument();
- expect(arrow(name)).toBeDisabled();
+ expect(arrow(name)).toHaveAttribute('aria-disabled', 'true');
// ...but gone from the accessibility tree, and so unreachable.
expect(screen.queryByRole('button', {name})).toBeNull();
}
diff --git a/packages/core/src/DateTimeInput/DateTimeInputTouch.test.tsx b/packages/core/src/DateTimeInput/DateTimeInputTouch.test.tsx
index 3b8b590b6c..912ba17f04 100644
--- a/packages/core/src/DateTimeInput/DateTimeInputTouch.test.tsx
+++ b/packages/core/src/DateTimeInput/DateTimeInputTouch.test.tsx
@@ -752,7 +752,7 @@ describe('DateTimeInput touch surface', () => {
openDateSheet();
const saveDateButton = getOnlyButton('Save date');
- expect(saveDateButton).toBeDisabled();
+ expect(saveDateButton).toHaveAttribute('aria-disabled', 'true');
fireEvent.click(saveDateButton);
expect(screen.getByRole('radio', {name: 'Date'})).toHaveAttribute(
'aria-checked',
@@ -768,11 +768,11 @@ describe('DateTimeInput touch surface', () => {
render(<ControlledDateTimeInput />);
openDateSheet();
const saveDateButton = getOnlyButton('Save date');
- expect(saveDateButton).toBeDisabled();
+ expect(saveDateButton).toHaveAttribute('aria-disabled', 'true');
fireEvent.click(getOnlyButton('Saturday, March 21, 2026'));
expect(dateField()).toHaveValue('March 21, 2026');
- expect(saveDateButton).not.toBeDisabled();
+ expect(saveDateButton).not.toHaveAttribute('aria-disabled');
fireEvent.click(saveDateButton);
expect(dateField()).toHaveAttribute('aria-expanded', 'false');
@@ -795,11 +795,11 @@ describe('DateTimeInput touch surface', () => {
);
openDateSheet();
const saveDateButton = getOnlyButton('Save date');
- expect(saveDateButton).not.toBeDisabled();
+ expect(saveDateButton).not.toHaveAttribute('aria-disabled');
fireEvent.click(getOnlyButton('Reset'));
expect(dateField()).toHaveValue('');
- expect(saveDateButton).toBeDisabled();
+ expect(saveDateButton).toHaveAttribute('aria-disabled', 'true');
fireEvent.click(saveDateButton);
expect(screen.getByRole('radio', {name: 'Date'})).toHaveAttribute(
diff --git a/packages/core/src/Drawer/Drawer.test.tsx b/packages/core/src/Drawer/Drawer.test.tsx
index ae374a1710..d8d535c7a2 100644
--- a/packages/core/src/Drawer/Drawer.test.tsx
+++ b/packages/core/src/Drawer/Drawer.test.tsx
@@ -510,15 +510,19 @@ describe('Drawer', () => {
</Drawer>
</ButtonGroup>,
);
- expect(screen.getByRole('button', {name: 'Outer member'})).toBeDisabled();
+ expect(
+ screen.getByRole('button', {name: 'Outer member'}),
+ ).toHaveAttribute('aria-disabled', 'true');
const independent = screen.getByRole('button', {name: 'Independent'});
- expect(independent).toBeEnabled();
+ expect(independent).not.toHaveAttribute('aria-disabled');
fireEvent.click(independent);
expect(press).toHaveBeenCalledOnce();
expect(
screen.getByRole('button', {name: 'Explicit disabled'}),
- ).toBeDisabled();
- expect(screen.getByRole('button', {name: 'Inner member'})).toBeDisabled();
+ ).toHaveAttribute('aria-disabled', 'true');
+ expect(
+ screen.getByRole('button', {name: 'Inner member'}),
+ ).toHaveAttribute('aria-disabled', 'true');
});
it('keeps unrelated application contexts flowing into drawer content', () => {
diff --git a/packages/core/src/DropdownMenu/__tests__/MenuButton.a11y.states.ts b/packages/core/src/DropdownMenu/__tests__/MenuButton.a11y.states.ts
index 7bd3ef42f6..5fe4c1102a 100644
--- a/packages/core/src/DropdownMenu/__tests__/MenuButton.a11y.states.ts
+++ b/packages/core/src/DropdownMenu/__tests__/MenuButton.a11y.states.ts
@@ -85,13 +85,14 @@ export const MENU_BUTTON_BINDING_STATES = [
},
{
id: 'dropdown-button-disabled',
- summary: 'a disabled DropdownMenu trigger that keeps its menu hidden',
+ summary:
+ 'a disabled DropdownMenu trigger that stays focusable and keeps its menu hidden',
storyId: story('dropdown-button-disabled'),
component: 'DropdownMenu',
label: 'Actions',
firstItem: 'Rename',
lastItem: 'Delete',
- facts: facts({operable: false, focusable: false}),
+ facts: facts({operable: false, focusable: true}),
disabled: true,
},
{
diff --git a/packages/core/src/IconButton/IconButton.doc.mjs b/packages/core/src/IconButton/IconButton.doc.mjs
index 9ca1e2060d..6805a4f8bf 100644
--- a/packages/core/src/IconButton/IconButton.doc.mjs
+++ b/packages/core/src/IconButton/IconButton.doc.mjs
@@ -55,7 +55,7 @@ export const docs = {
name: 'isDisabled',
type: 'boolean',
description:
- 'Disables the button. When a tooltip is present, uses aria-disabled instead of native disabled so the button stays focusable.',
+ 'Disables the button. Uses aria-disabled instead of native disabled so the button stays focusable.',
default: 'false',
},
{
@@ -249,7 +249,7 @@ export const docsDense = {
'resting shadow depth: none|low|med|high; raise for a floating action button (FAB)',
isLoading:
'shows loading spinner, blocks re-activation but stays focusable (aria-disabled, not native disabled)',
- isDisabled: 'disables button; uses aria-disabled when tooltip present',
+ isDisabled: 'disables button; uses aria-disabled instead of native disabled',
tooltip:
'tooltip on hover + keyboard focus; also describes the button unless it repeats the accessible name',
onClick: 'standard click handler',
diff --git a/packages/core/src/IconButton/IconButton.test.tsx b/packages/core/src/IconButton/IconButton.test.tsx
index b1f054739b..51b460c762 100644
--- a/packages/core/src/IconButton/IconButton.test.tsx
+++ b/packages/core/src/IconButton/IconButton.test.tsx
@@ -159,7 +159,7 @@ describe('IconButton', () => {
);
const button = screen.getByRole('button');
- expect(button).toBeDisabled();
+ expect(button).toHaveAttribute('aria-disabled', 'true');
await user.click(button);
expect(handleClick).not.toHaveBeenCalled();
});
diff --git a/packages/core/src/Layer/layerScopedContext.test.tsx b/packages/core/src/Layer/layerScopedContext.test.tsx
index 9f96f3f0ef..9afe2963d3 100644
--- a/packages/core/src/Layer/layerScopedContext.test.tsx
+++ b/packages/core/src/Layer/layerScopedContext.test.tsx
@@ -436,15 +436,21 @@ describe.each(boundaries)('%s provider boundary', (name, boundary) => {
)}
</ButtonGroup>,
);
- expect(screen.getByRole('button', {name: 'Outer member'})).toBeDisabled();
+ expect(screen.getByRole('button', {name: 'Outer member'})).toHaveAttribute(
+ 'aria-disabled',
+ 'true',
+ );
const independent = screen.getByRole('button', {name: 'Independent'});
- expect(independent).toBeEnabled();
+ expect(independent).not.toHaveAttribute('aria-disabled');
fireEvent.click(independent);
expect(press).toHaveBeenCalledOnce();
expect(
screen.getByRole('button', {name: 'Explicit disabled'}),
- ).toBeDisabled();
- expect(screen.getByRole('button', {name: 'Inner member'})).toBeDisabled();
+ ).toHaveAttribute('aria-disabled', 'true');
+ expect(screen.getByRole('button', {name: 'Inner member'})).toHaveAttribute(
+ 'aria-disabled',
+ 'true',
+ );
});
it('ends group-owned labels without changing the content input label', () => {
diff --git a/packages/core/src/Lightbox/Lightbox.test.tsx b/packages/core/src/Lightbox/Lightbox.test.tsx
index 2a48f08d02..a741f14375 100644
--- a/packages/core/src/Lightbox/Lightbox.test.tsx
+++ b/packages/core/src/Lightbox/Lightbox.test.tsx
@@ -317,8 +317,10 @@ describe('Lightbox', () => {
// focused control and drops focus to <body>.
const prev = screen.getByLabelText('Previous');
expect(prev).toBeInTheDocument();
- expect(prev).toBeDisabled();
- expect(screen.getByLabelText('Next')).not.toBeDisabled();
+ expect(prev).toHaveAttribute('aria-disabled', 'true');
+ expect(screen.getByLabelText('Next')).not.toHaveAttribute(
+ 'aria-disabled',
+ );
});
it('keeps next mounted and disabled on last item', () => {
@@ -332,8 +334,10 @@ describe('Lightbox', () => {
);
const next = screen.getByLabelText('Next');
expect(next).toBeInTheDocument();
- expect(next).toBeDisabled();
- expect(screen.getByLabelText('Previous')).not.toBeDisabled();
+ expect(next).toHaveAttribute('aria-disabled', 'true');
+ expect(screen.getByLabelText('Previous')).not.toHaveAttribute(
+ 'aria-disabled',
+ );
});
it('does not drop focus to <body> when navigating to the last item', () => {
diff --git a/packages/core/src/Pagination/Pagination.test.tsx b/packages/core/src/Pagination/Pagination.test.tsx
index 08e9422ee9..cf1248b367 100644
--- a/packages/core/src/Pagination/Pagination.test.tsx
+++ b/packages/core/src/Pagination/Pagination.test.tsx
@@ -430,10 +430,10 @@ describe('Pagination', () => {
);
expect(
screen.getByRole('button', {name: 'Go to first page'}),
- ).toBeDisabled();
+ ).toHaveAttribute('aria-disabled', 'true');
expect(
screen.getByRole('button', {name: 'Go to last page'}),
- ).not.toBeDisabled();
+ ).not.toHaveAttribute('aria-disabled');
rerender(
<Pagination
@@ -446,10 +446,10 @@ describe('Pagination', () => {
);
expect(
screen.getByRole('button', {name: 'Go to first page'}),
- ).not.toBeDisabled();
+ ).not.toHaveAttribute('aria-disabled');
expect(
screen.getByRole('button', {name: 'Go to last page'}),
- ).toBeDisabled();
+ ).toHaveAttribute('aria-disabled', 'true');
});
it('omits first/last when the total page count is unknown', async () => {
@@ -1096,10 +1096,10 @@ describe('Pagination', () => {
);
expect(
screen.getByRole('button', {name: 'Go to first page'}),
- ).toBeDisabled();
+ ).toHaveAttribute('aria-disabled', 'true');
expect(
screen.getByRole('button', {name: 'Go to last page'}),
- ).not.toBeDisabled();
+ ).not.toHaveAttribute('aria-disabled');
rerender(
<Pagination
@@ -1112,10 +1112,10 @@ describe('Pagination', () => {
);
expect(
screen.getByRole('button', {name: 'Go to last page'}),
- ).toBeDisabled();
+ ).toHaveAttribute('aria-disabled', 'true');
expect(
screen.getByRole('button', {name: 'Go to first page'}),
- ).not.toBeDisabled();
+ ).not.toHaveAttribute('aria-disabled');
});
it('hides first/last when hasFirstLast is false', () => {
@@ -1576,34 +1576,34 @@ describe('Pagination', () => {
render(<Pagination page={1} onChange={() => {}} totalPages={5} />);
expect(
screen.getByRole('button', {name: 'Go to previous page'}),
- ).toBeDisabled();
+ ).toHaveAttribute('aria-disabled', 'true');
});
it('disables next button on last page', () => {
render(<Pagination page={5} onChange={() => {}} totalPages={5} />);
expect(
screen.getByRole('button', {name: 'Go to next page'}),
- ).toBeDisabled();
+ ).toHaveAttribute('aria-disabled', 'true');
});
it('enables both buttons on middle page', () => {
render(<Pagination page={3} onChange={() => {}} totalPages={5} />);
expect(
screen.getByRole('button', {name: 'Go to previous page'}),
- ).not.toBeDisabled();
+ ).not.toHaveAttribute('aria-disabled');
expect(
screen.getByRole('button', {name: 'Go to next page'}),
- ).not.toBeDisabled();
+ ).not.toHaveAttribute('aria-disabled');
});
it('disables both buttons when only one page', () => {
render(<Pagination page={1} onChange={() => {}} totalPages={1} />);
expect(
screen.getByRole('button', {name: 'Go to previous page'}),
- ).toBeDisabled();
+ ).toHaveAttribute('aria-disabled', 'true');
expect(
screen.getByRole('button', {name: 'Go to next page'}),
- ).toBeDisabled();
+ ).toHaveAttribute('aria-disabled', 'true');
});
});
@@ -1616,28 +1616,28 @@ describe('Pagination', () => {
render(<Pagination page={1} onChange={() => {}} hasMore />);
expect(
screen.getByRole('button', {name: 'Go to next page'}),
- ).not.toBeDisabled();
+ ).not.toHaveAttribute('aria-disabled');
});
it('disables next when hasMore is false', () => {
render(<Pagination page={3} onChange={() => {}} hasMore={false} />);
expect(
screen.getByRole('button', {name: 'Go to next page'}),
- ).toBeDisabled();
+ ).toHaveAttribute('aria-disabled', 'true');
});
it('disables previous on first page with hasMore', () => {
render(<Pagination page={1} onChange={() => {}} hasMore />);
expect(
screen.getByRole('button', {name: 'Go to previous page'}),
- ).toBeDisabled();
+ ).toHaveAttribute('aria-disabled', 'true');
});
it('enables previous on page > 1 with hasMore', () => {
render(<Pagination page={2} onChange={() => {}} hasMore />);
expect(
screen.getByRole('button', {name: 'Go to previous page'}),
- ).not.toBeDisabled();
+ ).not.toHaveAttribute('aria-disabled');
});
});
@@ -1684,12 +1684,14 @@ describe('Pagination', () => {
);
expect(
screen.getByRole('button', {name: 'Go to previous page'}),
- ).toBeDisabled();
+ ).toHaveAttribute('aria-disabled', 'true');
expect(
screen.getByRole('button', {name: 'Go to next page'}),
- ).toBeDisabled();
+ ).toHaveAttribute('aria-disabled', 'true');
// Page buttons should also be disabled
- expect(screen.getByRole('button', {name: 'Go to page 1'})).toBeDisabled();
+ expect(
+ screen.getByRole('button', {name: 'Go to page 1'}),
+ ).toHaveAttribute('aria-disabled', 'true');
});
it('does not call onChange when disabled', async () => {
diff --git a/packages/core/src/PowerSearch/PowerSearchBottomSheet.test.tsx b/packages/core/src/PowerSearch/PowerSearchBottomSheet.test.tsx
index 1672f3f241..c56d240c8d 100644
--- a/packages/core/src/PowerSearch/PowerSearchBottomSheet.test.tsx
+++ b/packages/core/src/PowerSearch/PowerSearchBottomSheet.test.tsx
@@ -2000,7 +2000,7 @@ describe('PowerSearch Filters sheet (FR12)', () => {
within(sheet())
.getAllByRole('button', {name: 'Add filter'})
.find(button => button.closest('[role="tree"]') == null) as HTMLElement;
- expect(primary()).toBeDisabled();
+ expect(primary()).toHaveAttribute('aria-disabled', 'true');
fireEvent.click(
within(sheet()).getByRole('button', {name: '+ Add filter'}),
);
@@ -2014,7 +2014,7 @@ describe('PowerSearch Filters sheet (FR12)', () => {
fireEvent.click(
within(listbox).getByRole('option', {name: 'Open', hidden: true}),
);
- expect(primary()).toBeEnabled();
+ expect(primary()).not.toHaveAttribute('aria-disabled');
fireEvent.click(primary());
done();
expect(onChange).toHaveBeenCalledWith(
@@ -3090,13 +3090,13 @@ describe('PowerSearch value step (FR14–FR16)', () => {
expect(within(sheet()).queryByRole('button', {name: 'Remove'})).toBeNull();
expect(
within(sheet()).getByRole('button', {name: 'Add filter'}),
- ).toBeDisabled();
+ ).toHaveAttribute('aria-disabled', 'true');
fireEvent.change(within(sheet()).getByRole('textbox', {name: 'Value'}), {
target: {value: 'Ada'},
});
expect(
within(sheet()).getByRole('button', {name: 'Add filter'}),
- ).toBeEnabled();
+ ).not.toHaveAttribute('aria-disabled');
});
it('restores focus to the chosen field when creation is canceled', () => {
@@ -4602,11 +4602,11 @@ describe('PowerSearch sheet value types (FR17)', () => {
tapRow('Lines');
const input = within(sheet()).getByRole('spinbutton', {name: 'Value'});
const add = within(sheet()).getByRole('button', {name: 'Add filter'});
- expect(add).toBeDisabled();
+ expect(add).toHaveAttribute('aria-disabled', 'true');
fireEvent.input(input, {target: {value: '12'}});
expect(
within(sheet()).getByRole('button', {name: 'Add filter'}),
- ).toBeEnabled();
+ ).not.toHaveAttribute('aria-disabled');
fireEvent.blur(input);
addFilter();
done();
@@ -4626,7 +4626,7 @@ describe('PowerSearch sheet value types (FR17)', () => {
});
expect(
within(sheet()).getByRole('button', {name: 'Add filter'}),
- ).toBeDisabled();
+ ).toHaveAttribute('aria-disabled', 'true');
});
it('integer: clearing the field unstages the value and disables Add filter', () => {
@@ -4637,23 +4637,23 @@ describe('PowerSearch sheet value types (FR17)', () => {
fireEvent.input(input, {target: {value: '1'}});
expect(
within(sheet()).getByRole('button', {name: 'Add filter'}),
- ).toBeEnabled();
+ ).not.toHaveAttribute('aria-disabled');
// Delete the digit: nothing stands to confirm.
fireEvent.input(input, {target: {value: ''}});
expect(
within(sheet()).getByRole('button', {name: 'Add filter'}),
- ).toBeDisabled();
+ ).toHaveAttribute('aria-disabled', 'true');
fireEvent.click(within(sheet()).getByRole('button', {name: 'Add filter'}));
expect(onChange).not.toHaveBeenCalled();
// Not a number either: still nothing.
fireEvent.input(input, {target: {value: '-'}});
expect(
within(sheet()).getByRole('button', {name: 'Add filter'}),
- ).toBeDisabled();
+ ).toHaveAttribute('aria-disabled', 'true');
fireEvent.input(input, {target: {value: '12'}});
expect(
within(sheet()).getByRole('button', {name: 'Add filter'}),
- ).toBeEnabled();
+ ).not.toHaveAttribute('aria-disabled');
});
it('float: number input stages a decimal', () => {
diff --git a/packages/core/src/SnapPaging/SnapPaging.test.tsx b/packages/core/src/SnapPaging/SnapPaging.test.tsx
index 43a5818a45..b556fd3936 100644
--- a/packages/core/src/SnapPaging/SnapPaging.test.tsx
+++ b/packages/core/src/SnapPaging/SnapPaging.test.tsx
@@ -91,6 +91,11 @@ describe('useSnapPaging', () => {
});
});
+// A disabled Button stays focusable: it sets `aria-disabled`, not the native
+// `disabled` property.
+const isDisabled = (button: HTMLElement) =>
+ button.getAttribute('aria-disabled') === 'true';
+
describe('Carousel with hasSnap', () => {
function scroller() {
return screen
@@ -332,13 +337,13 @@ describe('Carousel with hasSnap', () => {
it('enables and disables each button as the held row leaves or reaches its edge, before the hand-back', () => {
const {report, start, end} = renderHeld();
// jsdom lays nothing out, so at rest the scroll offset gives no room.
- expect([start.disabled, end.disabled]).toEqual([true, true]);
+ expect([isDisabled(start), isDisabled(end)]).toEqual([true, true]);
report({offset: 0, travel: 600});
- expect([start.disabled, end.disabled]).toEqual([true, false]);
+ expect([isDisabled(start), isDisabled(end)]).toEqual([true, false]);
report({offset: 300, travel: 600});
- expect([start.disabled, end.disabled]).toEqual([false, false]);
+ expect([isDisabled(start), isDisabled(end)]).toEqual([false, false]);
report({offset: 599.5, travel: 600});
- expect([start.disabled, end.disabled]).toEqual([false, true]);
+ expect([isDisabled(start), isDisabled(end)]).toEqual([false, true]);
});
it('keeps the held edges for one frame after the hand-back, then reads the scroll offset again', async () => {
@@ -346,14 +351,14 @@ describe('Carousel with hasSnap', () => {
report({offset: 300, travel: 600});
report({offset: 300, travel: 600});
report(null);
- expect(start.disabled).toBe(false);
+ expect(isDisabled(start)).toBe(false);
await act(
async () =>
new Promise<void>(resolve => {
requestAnimationFrame(() => resolve());
}),
);
- expect(start.disabled).toBe(true);
+ expect(isDisabled(start)).toBe(true);
});
it('hands focus to the scroll area once, when the held row reaches the edge of the focused button', () => {
diff --git a/packages/core/src/Table/plugins/pagination/useTablePagination.test.tsx b/packages/core/src/Table/plugins/pagination/useTablePagination.test.tsx
index 88b2662131..df339cb7ac 100644
--- a/packages/core/src/Table/plugins/pagination/useTablePagination.test.tsx
+++ b/packages/core/src/Table/plugins/pagination/useTablePagination.test.tsx
@@ -548,7 +548,7 @@ describe('useTablePagination', () => {
const nextButton = screen.getByRole('button', {
name: 'Go to next page',
});
- expect(nextButton).not.toBeDisabled();
+ expect(nextButton).not.toHaveAttribute('aria-disabled');
});
it('passes onPageSizeChange and pageSizeOptions', () => {
@@ -610,8 +610,8 @@ describe('useTablePagination', () => {
const nextButton = screen.getByRole('button', {
name: 'Go to next page',
});
- expect(prevButton).toBeDisabled();
- expect(nextButton).toBeDisabled();
+ expect(prevButton).toHaveAttribute('aria-disabled', 'true');
+ expect(nextButton).toHaveAttribute('aria-disabled', 'true');
});
it('handles rapid page changes', async () => {
@@ -664,7 +664,7 @@ describe('useTablePagination', () => {
const prevButton = screen.getByRole('button', {
name: 'Go to previous page',
});
- expect(prevButton).toBeDisabled();
+ expect(prevButton).toHaveAttribute('aria-disabled', 'true');
});
});
});
diff --git a/packages/core/src/ToggleButton/ToggleButton.test.tsx b/packages/core/src/ToggleButton/ToggleButton.test.tsx
index f3c54951a5..2f3d54e99f 100644
--- a/packages/core/src/ToggleButton/ToggleButton.test.tsx
+++ b/packages/core/src/ToggleButton/ToggleButton.test.tsx
@@ -268,7 +268,7 @@ describe('ToggleButton', () => {
expect(pressedChangeAction).toHaveBeenCalledWith(true);
expect(button).toHaveAttribute('aria-pressed', 'true');
expect(button).toHaveAttribute('aria-busy', 'true');
- expect(button).not.toBeDisabled();
+ expect(button).not.toHaveAttribute('aria-disabled');
// Settle the action so the pending transition doesn't leak into later tests.
await act(async () => {
@@ -300,14 +300,14 @@ describe('ToggleButton', () => {
await user.click(button);
expect(button).toHaveAttribute('aria-busy', 'true');
- expect(button).not.toBeDisabled();
+ expect(button).not.toHaveAttribute('aria-disabled');
await act(async () => {
resolveAction?.();
await Promise.resolve();
});
expect(button).not.toHaveAttribute('aria-busy', 'true');
- expect(button).not.toBeDisabled();
+ expect(button).not.toHaveAttribute('aria-disabled');
});
it('interrupts an in-flight action on re-click (true -> false -> true)', async () => {
@@ -926,7 +926,10 @@ describe('disabled state', () => {
</ToggleButtonGroup>,
);
- expect(screen.getByRole('button', {name: 'List'})).toBeDisabled();
+ expect(screen.getByRole('button', {name: 'List'})).toHaveAttribute(
+ 'aria-disabled',
+ 'true',
+ );
await user.click(screen.getByRole('button', {name: 'List'}));
expect(handleChange).not.toHaveBeenCalled();
@@ -942,7 +945,9 @@ describe('disabled state', () => {
</ToggleButtonGroup>,
);
- expect(screen.getByRole('button', {name: 'Grid'})).toBeEnabled();
+ expect(screen.getByRole('button', {name: 'Grid'})).not.toHaveAttribute(
+ 'aria-disabled',
+ );
await user.click(screen.getByRole('button', {name: 'Grid'}));
expect(handleChange).toHaveBeenCalledWith('grid');
@@ -961,7 +966,10 @@ describe('disabled state', () => {
</ToggleButtonGroup>,
);
- expect(screen.getByRole('button', {name: 'List'})).toBeDisabled();
+ expect(screen.getByRole('button', {name: 'List'})).toHaveAttribute(
+ 'aria-disabled',
+ 'true',
+ );
await user.click(screen.getByRole('button', {name: 'List'}));
expect(handleChange).not.toHaveBeenCalled();
diff --git a/packages/core/src/ToggleButton/__tests__/ToggleButton.a11y.states.ts b/packages/core/src/ToggleButton/__tests__/ToggleButton.a11y.states.ts
index 13173ec0d6..b8ef97dc86 100644
--- a/packages/core/src/ToggleButton/__tests__/ToggleButton.a11y.states.ts
+++ b/packages/core/src/ToggleButton/__tests__/ToggleButton.a11y.states.ts
@@ -73,11 +73,11 @@ export const TOGGLE_BUTTON_BINDING_STATES = [
},
{
id: 'disabled-unpressed',
- summary: 'a natively disabled standalone toggle',
+ summary: 'a disabled standalone toggle that stays focusable',
storyId: 'a11y-toggle-button-pattern--disabled-unpressed',
visibleLabel: 'Bold',
renderKind: 'standalone',
- facts: facts(false, {operable: false, focusable: false, unavailable: true}),
+ facts: facts(false, {operable: false, unavailable: true}),
},
{
id: 'disabled-with-tooltip-pressed',
@@ -112,7 +112,7 @@ export const TOGGLE_BUTTON_BINDING_STATES = [
visibleLabel: 'List',
renderKind: 'single-group',
memberDisabled: true,
- facts: facts(false, {operable: false, focusable: false, unavailable: true}),
+ facts: facts(false, {operable: false, unavailable: true}),
},
{
id: 'single-group-disabled-member-silent',
@@ -121,7 +121,7 @@ export const TOGGLE_BUTTON_BINDING_STATES = [
visibleLabel: 'List',
renderKind: 'single-group',
groupDisabled: true,
- facts: facts(false, {operable: false, focusable: false, unavailable: true}),
+ facts: facts(false, {operable: false, unavailable: true}),
},
{
id: 'multiple-group-unpressed',
diff --git a/packages/core/src/Toolbar/Toolbar.test.tsx b/packages/core/src/Toolbar/Toolbar.test.tsx
index 16bf9bbd97..c15ec67bb4 100644
--- a/packages/core/src/Toolbar/Toolbar.test.tsx
+++ b/packages/core/src/Toolbar/Toolbar.test.tsx
@@ -14,6 +14,7 @@ import {act, fireEvent, render, screen, waitFor} from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import * as stylex from '@stylexjs/stylex';
import {Toolbar} from './Toolbar';
+import {Button} from '../Button/Button';
import {MoreMenu} from '../MoreMenu';
import {
paddingBlockStyles,
@@ -370,6 +371,42 @@ describe('Toolbar', () => {
expect(buttons[2]).toHaveAttribute('tabindex', '-1');
});
+ it('stays a single tab stop when every control is a disabled Button', async () => {
+ const user = userEvent.setup();
+ render(
+ <>
+ <button type="button">before</button>
+ <Toolbar
+ label="Formatting"
+ startContent={
+ <>
+ <Button label="Bold" isDisabled />
+ <Button label="Italic" isDisabled />
+ <Button label="Underline" isDisabled />
+ </>
+ }
+ />
+ <button type="button">after</button>
+ </>,
+ );
+ const bold = screen.getByRole('button', {name: 'Bold'});
+ expect(screen.getByRole('button', {name: 'Italic'})).toHaveAttribute(
+ 'tabindex',
+ '-1',
+ );
+ expect(screen.getByRole('button', {name: 'Underline'})).toHaveAttribute(
+ 'tabindex',
+ '-1',
+ );
+
+ await user.tab();
+ await user.tab();
+ expect(bold).toHaveFocus();
+ expect(bold).toHaveAttribute('aria-disabled', 'true');
+ await user.tab();
+ expect(screen.getByRole('button', {name: 'after'})).toHaveFocus();
+ });
+
it('keeps a link member in the arrow order and off the tab order', async () => {
const user = userEvent.setup();
render(
diff --git a/packages/core/src/Toolbar/Toolbar.tsx b/packages/core/src/Toolbar/Toolbar.tsx
index d8dfbe7636..5d24ab943f 100644
--- a/packages/core/src/Toolbar/Toolbar.tsx
+++ b/packages/core/src/Toolbar/Toolbar.tsx
@@ -26,7 +26,7 @@ import * as stylex from '@stylexjs/stylex';
import {spacingVars, sizeVars} from '../theme/tokens.stylex';
import {mergeProps} from '../utils';
import {Section} from '../Section/Section';
-import {useListFocus} from '../hooks/useListFocus';
+import {oneTabStopAmong, useInternalListFocus} from '../hooks/useListFocus';
import {useKeyboardHint} from '../hooks/useKeyboardHint';
import {SizeProvider} from '../SizeContext/SizeContext';
import {edgeCompSlot} from '../Layout/edgeCompensation.stylex';
@@ -202,6 +202,11 @@ export interface ToolbarProps extends BaseProps<HTMLDivElement> {
dividers?: ('top' | 'bottom' | 'start' | 'end')[];
}
+// `a[href]` catches a Button rendered with `href`.
+const TOOLBAR_ITEMS = 'button, input, a[href], [tabindex]';
+const TOOLBAR_BOUNDARY = '[role="toolbar"], [popover]';
+const toolbarTabStop = oneTabStopAmong(TOOLBAR_ITEMS, TOOLBAR_BOUNDARY);
+
/**
* General-purpose toolbar with start, center, and end content slots.
*
@@ -247,14 +252,16 @@ export function Toolbar({
const gapVar = spacingVars[spacingStepToVar[gap]] as string;
- const {listRef, handleKeyDown, handleFocus} = useListFocus<HTMLDivElement>({
- // `a[href]` catches a Button rendered with `href`.
- itemSelector: 'button, input, a[href], [tabindex]',
- boundarySelector: '[role="toolbar"], [popover]',
- orientation,
- hasRovingTabIndex: true,
- hasCaretGuard: true,
- });
+ const {listRef, handleKeyDown, handleFocus} =
+ useInternalListFocus<HTMLDivElement>({
+ itemSelector: TOOLBAR_ITEMS,
+ boundarySelector: TOOLBAR_BOUNDARY,
+ orientation,
+ hasRovingTabIndex: true,
+ hasCaretGuard: true,
+ // A read-only toolbar of disabled controls stays one Tab stop.
+ tabStopOrder: toolbarTabStop,
+ });
const {
hintElement,
diff --git a/packages/core/src/hooks/useListFocus.ts b/packages/core/src/hooks/useListFocus.ts
index aaaacd2169..19346e1f74 100644
--- a/packages/core/src/hooks/useListFocus.ts
+++ b/packages/core/src/hooks/useListFocus.ts
@@ -355,6 +355,39 @@ export function useListFocus<T extends HTMLElement = HTMLElement>(
return useInternalListFocus<T>(options);
}
+function isDisabledItem(el: HTMLElement): boolean {
+ return (
+ el.getAttribute('aria-disabled') === 'true' ||
+ (el as HTMLButtonElement).disabled === true ||
+ el.hasAttribute('disabled')
+ );
+}
+
+/**
+ * A `tabStopOrder` for a group whose disabled items stay focusable, such as a
+ * row of disabled Buttons. The group keeps one Tab stop while every item is
+ * disabled: the item that holds the stop, else the first enabled item, else
+ * the first item. With an enabled item it places the stop as the default does.
+ */
+export function oneTabStopAmong(
+ itemSelector: string,
+ boundarySelector: string,
+): (list: HTMLElement) => HTMLElement[] {
+ return list => {
+ const items = Array.from(
+ list.querySelectorAll<HTMLElement>(itemSelector),
+ ).filter(
+ el => !isHiddenWithin(el, list) && el.closest(boundarySelector) === list,
+ );
+ const enabled = items.filter(el => !isDisabledItem(el));
+ const candidates = enabled.length > 0 ? enabled : items;
+ const stop =
+ candidates.find(el => el.getAttribute('tabindex') === '0') ??
+ candidates[0];
+ return stop == null ? items : [stop, ...items.filter(el => el !== stop)];
+ };
+}
+
/**
* {@link useListFocus} with the Core-only {@link InternalListFocusOptions}.
* Not re-exported from `hooks/index.ts`.
@@ -383,13 +416,7 @@ export function useInternalListFocus<T extends HTMLElement = HTMLElement>(
* A `.focus()` call on such an element silently no-ops, so navigation must
* skip these to avoid freezing on a disabled item (menus-4, navigation-5).
*/
- const isItemDisabled = useCallback((el: HTMLElement): boolean => {
- return (
- el.getAttribute('aria-disabled') === 'true' ||
- (el as HTMLButtonElement).disabled === true ||
- el.hasAttribute('disabled')
- );
- }, []);
+ const isItemDisabled = isDisabledItem;
/**
* Get all focusable items in the list.
diff --git a/packages/lab/src/Comments/CommentComposer.test.tsx b/packages/lab/src/Comments/CommentComposer.test.tsx
index cbca3126a4..9cc53d3bdd 100644
--- a/packages/lab/src/Comments/CommentComposer.test.tsx
+++ b/packages/lab/src/Comments/CommentComposer.test.tsx
@@ -106,7 +106,7 @@ describe('CommentComposer', () => {
<CommentComposer value="" onChange={() => {}} onSubmit={onSubmit} />,
);
const post = screen.getByRole('button', {name: /send/i});
- expect(post).toBeDisabled();
+ expect(post).toHaveAttribute('aria-disabled', 'true');
rerender(
<CommentComposer
value="Looks good"
diff --git a/packages/lab/src/Comments/Comments.test.tsx b/packages/lab/src/Comments/Comments.test.tsx
index 693c22de40..0b9d8f8650 100644
--- a/packages/lab/src/Comments/Comments.test.tsx
+++ b/packages/lab/src/Comments/Comments.test.tsx
@@ -505,7 +505,7 @@ describe('Comments rendering', () => {
const article = articleByAuthor('Avery Kim');
expect(
within(article).getByRole('button', {name: 'Like: 2'}),
- ).toBeDisabled();
+ ).toHaveAttribute('aria-disabled', 'true');
expect(within(article).queryByRole('button', {name: 'Reply'})).toBeNull();
expect(
within(article).queryByRole('button', {
diff --git a/packages/lab/src/ListInput/ListInput.test.tsx b/packages/lab/src/ListInput/ListInput.test.tsx
index 311a39016f..96a9fc9197 100644
--- a/packages/lab/src/ListInput/ListInput.test.tsx
+++ b/packages/lab/src/ListInput/ListInput.test.tsx
@@ -973,7 +973,10 @@ describe('ListInput', () => {
renderListInput({maxItems: 2, onChange});
- expect(screen.getByRole('button', {name: 'Add guest'})).toBeDisabled();
+ expect(screen.getByRole('button', {name: 'Add guest'})).toHaveAttribute(
+ 'aria-disabled',
+ 'true',
+ );
const remove = screen.getByRole('button', {name: 'Remove guest 1'});
expect(remove).toBeEnabled();
@@ -1354,7 +1357,10 @@ describe('ListInput', () => {
for (const field of screen.getAllByRole('textbox')) {
expect(field).toBeDisabled();
}
- expect(screen.getByRole('button', {name: /add guest/i})).toBeDisabled();
+ expect(screen.getByRole('button', {name: /add guest/i})).toHaveAttribute(
+ 'aria-disabled',
+ 'true',
+ );
expect(
screen.getByRole('button', {name: 'Reorder guest 1'}),
).toBeDisabled();
diff --git a/packages/lab/src/TransferList/TransferListSelector.test.tsx b/packages/lab/src/TransferList/TransferListSelector.test.tsx
index 82e5629b37..5eaccff7f4 100644
--- a/packages/lab/src/TransferList/TransferListSelector.test.tsx
+++ b/packages/lab/src/TransferList/TransferListSelector.test.tsx
@@ -487,7 +487,7 @@ describe('TransferListSelector', () => {
});
expect(cancel).toBeEnabled();
expect(fieldset).not.toContainElement(cancel);
- expect(apply).toBeDisabled();
+ expect(apply).toHaveAttribute('aria-disabled', 'true');
expect(
screen.getByRole('combobox', {name: 'Visible fields'}),
).toHaveAttribute('aria-disabled', 'true');
@@ -515,7 +515,7 @@ describe('TransferListSelector', () => {
).toBeEnabled();
expect(
within(dialog).getByRole('button', {name: 'Apply', hidden: true}),
- ).toBeDisabled();
+ ).toHaveAttribute('aria-disabled', 'true');
});
it('keeps focus on the activated row control while a change is pending', async () => {
diff --git a/packages/richtext/src/RichTextEditor.test.tsx b/packages/richtext/src/RichTextEditor.test.tsx
index d1fe8e7a8e..1ffe4716bd 100644
--- a/packages/richtext/src/RichTextEditor.test.tsx
+++ b/packages/richtext/src/RichTextEditor.test.tsx
@@ -1525,7 +1525,10 @@ describe('RichTextEditorToolbar', () => {
toolbar={<RichTextEditorToolbar />}
/>,
);
- expect(screen.getByRole('button', {name: 'Bold'})).toBeDisabled();
+ expect(screen.getByRole('button', {name: 'Bold'})).toHaveAttribute(
+ 'aria-disabled',
+ 'true',
+ );
});
it('renders a theme-registered icon override for a richtext:* key', () => {
@@ -2385,12 +2388,17 @@ describe('toolbar follows the editable props after mount', () => {
toolbar={<RichTextEditorToolbar />}
/>,
);
- expect(screen.getByRole('button', {name: 'Bold'})).toBeDisabled();
+ expect(screen.getByRole('button', {name: 'Bold'})).toHaveAttribute(
+ 'aria-disabled',
+ 'true',
+ );
rerender(
<RichTextEditor label="Notes" toolbar={<RichTextEditorToolbar />} />,
);
- expect(screen.getByRole('button', {name: 'Bold'})).toBeEnabled();
+ expect(screen.getByRole('button', {name: 'Bold'})).not.toHaveAttribute(
+ 'aria-disabled',
+ );
rerender(
<RichTextEditor
@@ -2399,7 +2407,10 @@ describe('toolbar follows the editable props after mount', () => {
toolbar={<RichTextEditorToolbar />}
/>,
);
- expect(screen.getByRole('button', {name: 'Bold'})).toBeDisabled();
+ expect(screen.getByRole('button', {name: 'Bold'})).toHaveAttribute(
+ 'aria-disabled',
+ 'true',
+ );
});
});