Skip to content

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

TypeScript

fix(core): TabList marks the selected tab with a generic aria-current (#5347)

Cindy Zhang3b74294664be
diff --git a/.changeset/tab-generic-aria-current.md b/.changeset/tab-generic-aria-current.md
new file mode 100644
index 0000000000..5b4c2220d5
--- /dev/null
+++ b/.changeset/tab-generic-aria-current.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] TabList: the selected tab now carries `aria-current="true"` — ARIA's generic "current item within a set" — instead of `aria-current="page"`. The strip is a `<nav>` and stays one, but it is used to switch views in place at least as often as it is used to navigate, and on those uses `page` asserted a page change that never happened. Assistive tech announced the selected tab as the _current page_ even when nothing had navigated; it now announces it as the _current item_, which is true either way. A tab given an `href` still renders an anchor and still reads as a link — its current marker is just less specific than it was. No role changes and no new props. (#5347)
+
+@cixzhang
diff --git a/packages/core/src/TabList/Tab.tsx b/packages/core/src/TabList/Tab.tsx
index 88bff13928..e1943508a1 100644
--- a/packages/core/src/TabList/Tab.tsx
+++ b/packages/core/src/TabList/Tab.tsx
@@ -260,7 +260,11 @@ export function Tab({
...(isLabelHidden ? {'aria-label': label} : {}),
[EDGE_COMP_ATTR]: '',
'data-tab-value': value,
- 'aria-current': isSelected ? ('page' as const) : undefined,
+ // Generic `true` ("the current item within a set"), not `page`: the strip
+ // switches views in place at least as often as it navigates, and claiming
+ // "current page" when no page changed is a false statement to a screen
+ // reader. Stays truthful for the `href` case too, just less specific.
+ 'aria-current': isSelected ? ('true' as const) : undefined,
// Roving tabindex: the tab strip is a single Tab stop. The selected tab is
// the tabbable one; the rest are reachable via arrow keys (handled by
// TabList's onKeyDown). When no tab is selected, TabList's repair effect
diff --git a/packages/core/src/TabList/TabList.test.tsx b/packages/core/src/TabList/TabList.test.tsx
index b14bcb1771..9ad44bc2d4 100644
--- a/packages/core/src/TabList/TabList.test.tsx
+++ b/packages/core/src/TabList/TabList.test.tsx
@@ -106,7 +106,7 @@ describe('TabList', () => {
);
});
- it('marks selected tab with aria-current', () => {
+ it('marks selected tab with a generic aria-current, not "page"', () => {
render(
<TabList value="home" onChange={() => {}}>
<Tab value="home" label="Home" />
@@ -116,13 +116,30 @@ describe('TabList', () => {
expect(screen.getByRole('button', {name: 'Home'})).toHaveAttribute(
'aria-current',
- 'page',
+ 'true',
);
expect(screen.getByRole('button', {name: 'Settings'})).not.toHaveAttribute(
'aria-current',
);
});
+ it('marks a selected link tab with the same generic aria-current', () => {
+ render(
+ <TabList value="home" onChange={() => {}}>
+ <Tab value="home" label="Home" href="/home" />
+ <Tab value="settings" label="Settings" href="/settings" />
+ </TabList>,
+ );
+
+ expect(screen.getByRole('link', {name: 'Home'})).toHaveAttribute(
+ 'aria-current',
+ 'true',
+ );
+ expect(screen.getByRole('link', {name: 'Settings'})).not.toHaveAttribute(
+ 'aria-current',
+ );
+ });
+
it('calls onChange when a tab is clicked', async () => {
const user = userEvent.setup();
const handleChange = vi.fn();
@@ -148,7 +165,7 @@ describe('TabList', () => {
expect(screen.getByRole('button', {name: 'Home'})).toHaveAttribute(
'aria-current',
- 'page',
+ 'true',
);
rerender(
@@ -163,7 +180,7 @@ describe('TabList', () => {
);
expect(screen.getByRole('button', {name: 'Settings'})).toHaveAttribute(
'aria-current',
- 'page',
+ 'true',
);
});