An open source design system that's fully customizable and agent ready
TypeScript
fix(core): a disabled Item swipe action stays focusable (#9211)
Parinith30e724b45f3c
diff --git a/.changeset/item-swipe-entry-focusable-disabled.md b/.changeset/item-swipe-entry-focusable-disabled.mdnew file mode 100644index 0000000000..0b7644404f--- /dev/null+++ b/.changeset/item-swipe-entry-focusable-disabled.md@@ -0,0 +1,7 @@+---+'@astryxdesign/core': patch+---++[fix] A disabled swipe action on an `Item` row now stays focusable while the row is swiped open. Before, it rendered a `<button>` with the native `disabled` attribute, so Tab skipped it and a keyboard or screen-reader user could not reach it to learn it exists. Now it exposes `aria-disabled="true"` and keeps its Tab stop, while a click, Enter or Space still runs no `onActivate`, leaves the row open, and does not reach the row's own `onClick` (`spec:AST-085` FR1, FR2). No API changes.++@parinith-webdiff --git a/packages/core/src/Item/Item.test.tsx b/packages/core/src/Item/Item.test.tsxindex 235ffd94fc..e124c5d34b 100644--- a/packages/core/src/Item/Item.test.tsx+++ b/packages/core/src/Item/Item.test.tsx@@ -1234,6 +1234,36 @@ describe('swipeActions', () => {expect(onClick).not.toHaveBeenCalled();});+ it('keeps a disabled entry focusable but inert on an open row (spec:AST-085 FR1, FR2)', () => {+ const onActivate = vi.fn();+ const onClick = vi.fn();+ const {row} = renderRow({+ leading: [{label: 'Unread', onActivate, isDisabled: true}],+ onClick,+ });+ touch(row, 'pointerDown', 10);+ touch(row, 'pointerMove', 30);+ touch(row, 'pointerMove', 45);+ touch(row, 'pointerMove', 60);+ touch(row, 'pointerUp', 60);+ settled();+ expect(travelOf(row)).toBe('72px');+ const button = screen.getByRole('button', {name: 'Unread'});+ // Exposed through aria-disabled, never the native attribute, so it+ // keeps its place in the focus order.+ expect(button).toHaveAttribute('aria-disabled', 'true');+ expect(button).not.toHaveAttribute('disabled');+ button.focus();+ expect(button).toHaveFocus();+ // Inert: the click Enter and Space send runs nothing, leaves the row+ // open, and does not reach the row's own primary.+ fireEvent.click(button);+ settled();+ expect(onActivate).not.toHaveBeenCalled();+ expect(travelOf(row)).toBe('72px');+ expect(onClick).not.toHaveBeenCalled();+ });+it('holds the row out after a tapped entry with hasRemoval', () => {const onActivate = vi.fn();const {row} = renderRow({diff --git a/packages/core/src/Item/ItemSwipeLayer.tsx b/packages/core/src/Item/ItemSwipeLayer.tsxindex 4c5a010d04..7df1e81a6b 100644--- a/packages/core/src/Item/ItemSwipeLayer.tsx+++ b/packages/core/src/Item/ItemSwipeLayer.tsx@@ -31,6 +31,7 @@ import {} from '../theme/tokens.stylex';import {mergeProps} from '../utils/mergeProps';import {themeProps} from '../utils/themeProps';+import {disabledInteractionProps} from '../utils/disabledInteraction';import {focusOutlineProps} from '../utils/focusOutline.stylex';import {useMediaQuery} from '../hooks/useMediaQuery';import {@@ -307,13 +308,19 @@ export default function ItemSwipeLayer({<buttonkey={entry.id ?? entry.label}type="button"- disabled={entry.isDisabled === true}+ aria-disabled={entry.isDisabled === true ? true : undefined}onClick={() =>swipe.activateEntry(() => {void entry.onActivate();return entry.hasRemoval === true;})}+ // A disabled entry stays focusable while the row rests open but+ // is inert: it runs no `onActivate` and its click does not+ // reach the row (spec:AST-085 FR1, FR2).+ {...(entry.isDisabled === true+ ? disabledInteractionProps<HTMLButtonElement>()+ : null)}{...mergeProps(themeProps('item-swipe-action', {variant}),focusOutlineProps.focusVisible(