When to use it#
- Use tabs when one page holds a few parts of the same thing, such as the details, documents and history of a case, and people need one part at a time.
- Keep the labels short and in the same style. Content that people must read together doesn’t belong in tabs.
- Not for going to another page: use Navigation with
kv-navigation--horizontal. A tab never changes the URL. - Not for showing and hiding one block of text: use a Disclosure. Don’t put interactive content, such as a close button, inside a tab.
Example#
Building permit application for 4 Strand Road. The case awaits review.
Drawings, a site plan and a control plan have arrived.
The application arrived on 2 September. More information was requested on 9 September.
import { Tabs } from '@kvirn-ui/react'
import { useTabsTexts } from './texts.ts'
export function DefaultTabs() {
const { texts } = useTabsTexts()
return (
<Tabs.Root defaultValue="details">
<Tabs.List aria-label={texts.list}>
<Tabs.Tab value="details">{texts.details}</Tabs.Tab>
<Tabs.Tab value="documents">{texts.documents}</Tabs.Tab>
<Tabs.Tab value="history">{texts.history}</Tabs.Tab>
</Tabs.List>
<Tabs.Panel value="details">
<p>{texts.detailsText}</p>
</Tabs.Panel>
<Tabs.Panel value="documents">
<p>{texts.documentsText}</p>
</Tabs.Panel>
<Tabs.Panel value="history">
<p>{texts.historyText}</p>
</Tabs.Panel>
</Tabs.Root>
)
}Use cases#
Panels that are slow to show
By default, the arrow keys select the tab they move to, and its panel shows at once. If showing a panel loads data or is heavy, arrowing through the tabs would load every panel on the way. Set activationMode to manual: the arrows only move focus, and Enter or Space selects.
Building permit application for 4 Strand Road. The case awaits review.
Drawings, a site plan and a control plan have arrived.
The application arrived on 2 September. More information was requested on 9 September.
import { Tabs } from '@kvirn-ui/react'
import { useTabsTexts } from './texts.ts'
export function ManualActivation() {
const { texts } = useTabsTexts()
return (
<Tabs.Root defaultValue="details" activationMode="manual">
<Tabs.List aria-label={texts.list}>
<Tabs.Tab value="details">{texts.details}</Tabs.Tab>
<Tabs.Tab value="documents">{texts.documents}</Tabs.Tab>
<Tabs.Tab value="history">{texts.history}</Tabs.Tab>
</Tabs.List>
<Tabs.Panel value="details">
<p>{texts.detailsText}</p>
</Tabs.Panel>
<Tabs.Panel value="documents">
<p>{texts.documentsText}</p>
</Tabs.Panel>
<Tabs.Panel value="history">
<p>{texts.historyText}</p>
</Tabs.Panel>
</Tabs.Root>
)
}Props in this example:
activationModeon Tabs.Root
Information: Implement like this
Every panel stays in the page, so render a heavy panel’s content only while it is selected.
<Tabs.Root value={value} onValueChange={setValue}>
<Tabs.Panel value="history">{value === 'history' && <History />}</Tabs.Panel>
</Tabs.Root>A column of tabs beside the content
Use it when there are many tabs with short names, such as the sections of an application. The arrow keys become Down and Up, and the list gets aria-orientation.
Maria Lind, 4 Strand Road.
Strand 1:23, 12 square metres of new building.
Three files, 2.4 MB in total.
import { Tabs } from '@kvirn-ui/react'
import { useTabsTexts } from './texts.ts'
export function VerticalTabs() {
const { texts } = useTabsTexts()
return (
<Tabs.Root defaultValue="applicant" orientation="vertical">
<Tabs.List aria-label={texts.sections}>
<Tabs.Tab value="applicant">{texts.applicant}</Tabs.Tab>
<Tabs.Tab value="property">{texts.property}</Tabs.Tab>
<Tabs.Tab value="attachments">{texts.attachments}</Tabs.Tab>
</Tabs.List>
<Tabs.Panel value="applicant">
<p>{texts.applicantText}</p>
</Tabs.Panel>
<Tabs.Panel value="property">
<p>{texts.propertyText}</p>
</Tabs.Panel>
<Tabs.Panel value="attachments">
<p>{texts.attachmentsText}</p>
</Tabs.Panel>
</Tabs.Root>
)
}Props in this example:
orientationon Tabs.Root
A tab that can’t be used right now
Sometimes a tab can’t be used until something has happened, such as a decision on a case. People can still reach it with the arrow keys, and a screen reader (software that reads the screen aloud) says it is unavailable, so they can find it. Link the reason to it with aria-describedby.
The decision tab opens when the case has been decided.
Building permit application for 4 Strand Road. The case awaits review.
The decision is not ready yet.
import { Tabs } from '@kvirn-ui/react'
import { useId } from 'react'
import { useTabsTexts } from './texts.ts'
export function DisabledTab() {
const { texts } = useTabsTexts()
const reasonId = useId()
return (
<Tabs.Root defaultValue="details">
<Tabs.List aria-label={texts.list}>
<Tabs.Tab value="details">{texts.details}</Tabs.Tab>
<Tabs.Tab value="decision" disabled aria-describedby={reasonId}>
{texts.decision}
</Tabs.Tab>
</Tabs.List>
<p id={reasonId}>{texts.decisionReason}</p>
<Tabs.Panel value="details">
<p>{texts.detailsText}</p>
</Tabs.Panel>
<Tabs.Panel value="decision">
<p>{texts.decisionText}</p>
</Tabs.Panel>
</Tabs.Root>
)
}Props in this example:
disabledon Tabs.Tab
Warning: Don't forget
Disable a tab sparingly, and say why in text people can read, as in What you need to do.
Choosing the tab from your own code
Use it when something else on the page must select a tab or read which one is selected. You hold the value and change it from onValueChange, which only reports what the user did.
Building permit application for 4 Strand Road. The case awaits review.
The application arrived on 2 September. More information was requested on 9 September.
Selected tab: Details
import { Button, Tabs } from '@kvirn-ui/react'
import { useState } from 'react'
import { useTabsTexts } from './texts.ts'
export function ControlledTabs() {
const { texts } = useTabsTexts()
const [value, setValue] = useState('details')
return (
<div>
<Tabs.Root value={value} onValueChange={setValue}>
<Tabs.List aria-label={texts.list}>
<Tabs.Tab value="details">{texts.details}</Tabs.Tab>
<Tabs.Tab value="history">{texts.history}</Tabs.Tab>
</Tabs.List>
<Tabs.Panel value="details">
<p>{texts.detailsText}</p>
</Tabs.Panel>
<Tabs.Panel value="history">
<p>{texts.historyText}</p>
</Tabs.Panel>
</Tabs.Root>
<p>
{texts.selected} <strong>{value === 'details' ? texts.details : texts.history}</strong>
</p>
<Button onClick={() => setValue('history')}>{texts.showHistory}</Button>
</div>
)
}Props in this example:
valueon Tabs.RootonValueChangeon Tabs.Root
Information: Did you know?
Tabs never change the URL, so Back leaves the page. If each part needs its own address, use Navigation.
A panel that starts with a link or a field
A panel is a Tab stop (a place where the Tab key stops, set with tabindex="0"), so keyboard users can reach a panel that holds only text and scroll it. When its first content is a link or a field, pass tabIndex={-1} so Tab goes straight to that link or field and the panel isn’t an extra stop.
Building permit application for 4 Strand Road. The case awaits review.
import { Link, Tabs } from '@kvirn-ui/react'
import { useTabsTexts } from './texts.ts'
export function FocusablePanel() {
const { texts } = useTabsTexts()
return (
<Tabs.Root defaultValue="decision">
<Tabs.List aria-label={texts.list}>
<Tabs.Tab value="details">{texts.details}</Tabs.Tab>
<Tabs.Tab value="decision">{texts.decision}</Tabs.Tab>
</Tabs.List>
<Tabs.Panel value="details">
<p>{texts.detailsText}</p>
</Tabs.Panel>
<Tabs.Panel value="decision" tabIndex={-1}>
<Link.Root href="#example">{texts.decisionLink}</Link.Root>
</Tabs.Panel>
</Tabs.Root>
)
}Props in this example:
tabIndexon Tabs.Panel
Accessibility#
What it does for you#
- APG pattern: Tabs, with the keyboard practice for a composite widget (one Tab stop, a roving
tabindex). - Deviations: two, both approved by the maintainer. (1) A panel has
tabindex="0"by default. APG sets it only when the panel has no focusable content, and a headless panel cannot know its first content without scanning the DOM. One redundant Tab stop is the lesser evil: no default would strand keyboard users on a panel of scrolling text (2.1.1). A panel that starts with a focusable element passestabIndex={-1}. (2) A disabled tab stays focusable (aria-disabled="true", as the project's keyboard rules say for items of a composite widget), and automatic activation never selects it, so focus and selection can differ. APG is silent on both. - Native elements used:
<button type="button">for a tab,<div>for the root, the list and a panel. The roles are explicit:tablist,tabandtabpanel.
Tabs show one panel of content at a time, with a list of tabs to switch between them: a keyboard user passes the tab list with one Tab press, moves between the tabs with the arrow keys and reaches the selected panel with the next Tab, and a screen reader user usually hears "tab, 2 of 3, selected". Tabs change content on the same page. For links to other pages, use Navigation (kv-navigation--horizontal): a tab never navigates.
| Part | Element / role | ARIA | Notes |
|---|---|---|---|
| Tabs.Root | <div> | none. data-orientation | Owns the selected value. No role: it is a plain container for the list and the panels |
| Tabs.List | <div> → tablist | aria-label or aria-labelledby (yours). aria-orientation="vertical" only when vertical | Name it when a page has more than one. Horizontal is the default of the role, so aria-orientation is only set when vertical. Owns the arrow keys, Home and End |
| Tabs.Tab | <button type="button"> → tab | aria-selected (true or false, always set), aria-controls (its panel's id), aria-disabled="true" when disabled | Never a native disabled: a disabled tab stays focusable. Its name is its text. data-selected and data-disabled for the theme. |
| Tabs.Panel | <div> → tabpanel | aria-labelledby (its tab's id), hidden while it isn't selected, tabindex="0" | Named by its tab. Always rendered, with hidden while it isn't selected, so every aria-controls and aria-labelledby resolves. Not inert, not unmounted. A tabIndex you pass wins: -1 for a panel that starts with a focusable element. data-selected for the theme |
| every tab | – | tabindex="0" on one, -1 on the others | Roving tabindex. DOM focus is on the tab, never aria-activedescendant. The one tab with 0 is the focused tab while focus is in the list, and the selected tab otherwise. Test: tabs.test.tsx › roving tabindex |
| the ids | – | id on every tab and panel | From the root's useId() and the tab's value, each character outside [A-Za-z0-9-] escaped as _<hex code point>_, so ids are unique and an IDREF has no space. Not an index: a panel needs its tab's id on the first server render, before anything registers, and an index breaks when the tabs reorder. Test: tabs-ids.test.ts, tabs.test.tsx › every tab controls its panel and every panel is named by its tab, for values with spaces and punctuation too |
Tabs have no strings of their own: every name is the consumer's, from their translations. They announce nothing: selection is in aria-selected, and a screen reader says "tab, 2 of 3, selected" from the roles.
One of value and defaultValue is required (by the types). There is no "first tab" fallback, because the tabs register after the server render, and the server markup must already say which tab is selected and which is the Tab stop. A value that no tab has leaves no Tab stop and shows no panel, so a dev warning fires (tabs-value-without-tab:<value>, 2.1.1, 4.1.2). So does a tab with no panel, or a panel with no tab (tabs-unpaired:<value>, 4.1.2).
It announces nothing.
What you need to do#
- Name the list with
aria-labelfrom your translations, oraria-labelledby, when a page has more than one set of tabs, so a screen reader user can tell them apart. - Keep the labels short, and in the same register ("Details", "History"). A long label wraps inside its tab and never scrolls the list sideways (1.4.10).
- Give every tab a panel and every panel a tab, with the same
value, and givevalueordefaultValuethe value of a tab. Render everyTabs.Panel: do not unmount the ones that aren't selected, because the tab'saria-controlswould point at nothing. For lazy content, render a panel's children only while its tab is selected, using your ownvalue. - Use
activationMode="manual"only for slow panels. Otherwise keep the default. - Pass
tabIndex={-1}to a panel that starts with a focusable element (a link, a button or a field), so Tab goes straight to it and the panel is not a redundant stop. A panel with only text keeps itstabindex="0". - Use a tab only for content on the same page. For links to other pages, or a trail through a service, use
Navigation(kv-navigation--horizontal) or a stepper. A tab never changes the URL. - Disable a tab sparingly, and say why where users can read it: a disabled tab is dimmed and read as unavailable, and it stays focusable so it can be found.
- The panel is not a landmark and has no heading of its own. The page's heading outline continues inside it: don't skip levels.
- Don't put interactive content in a tab. A close button or a menu inside a tab is not supported, and the tab's click would also fire for it.
Warning: Don't forget
Name the tab list with aria-label or aria-labelledby when a page has more than one set of tabs, so a screen reader user can tell them apart (4.1.2 Name, Role, Value, level A). Every example on this page does it.
Visual and modes#
- Focus indicator: a tab and a panel each show the same focus ring as a link: at least 2px thick, set off from the element (2.4.7 Focus Visible, level AA; 2.4.13 Focus Appearance, level AAA).
- Target size: a tab is at least 24 × 24 CSS px, and taller in the default theme (2.5.8). A story asserts that threshold, also in the compact density.
- State without colour: the selected tab is bold and has a straight bar at its edge, not colour alone (1.4.1, 1.4.11). A disabled tab is dimmed text and
aria-disabled. - forced-colors behaviour (Windows contrast themes): the bar, the line under the list and the text use the system's colours, a disabled tab uses the system's disabled-text colour, and the focus ring uses its highlight colour. The forced-colours sweep checks that every tab keeps a visible boundary and shows a focus indicator when it has focus (1.4.11).
- reduced-motion behaviour: nothing animates, and the reduced-motion sweep checks that no animation keeps looping (2.3.3).
- Reflow: the list wraps, row by row, and never scrolls sideways. A long label wraps inside its tab. A vertical set stacks below 40rem (1.4.10). The reflow sweep runs every story at 320 CSS px and fails on horizontal overflow, and one story uses a long Finnish text. The text-spacing sweep applies the 1.4.12 spacing and fails on a box that clips its content.
- Right to left: logical properties only, and the arrows flip (above). The bar of a vertical tab is at the inline end.
Focus management#
- Initial focus: not moved. Tab enters at the selected tab.
- Trap: no. Tab and Shift+Tab always leave the list (2.1.2).
- Restore to: not applicable. Selecting a tab never moves focus: it stays on the tab, and the panel is the next Tab stop.
- Never obscured by: the tab list is not sticky by default. A sticky header above the tabs is the page's to allow for with
scroll-padding(2.4.11).
Information: Did you know?
Choosing a tab never moves focus. It stays on the tab, and the next Tab press goes to the panel. A keyboard user moves from the tabs to the panel with one Tab press.
WCAG success criteria#
- 1.3.1 Info and Relationships (A):
tablist,tabandtabpanel, a tab and its panel tied byaria-controlsandaria-labelledby. - 1.4.1 Use of Color (A), 1.4.11 Non-text Contrast (AA): the selected tab is a bar and a weight, and the default theme's bar and focus ring are held to a 3:1 contrast in every theme.
- 1.4.10 Reflow (AA): the list wraps and never scrolls sideways.
- 2.1.1 Keyboard (A), 2.1.2 No Keyboard Trap (A): every tab and panel is reachable, and Tab always leaves.
- 2.4.3 Focus Order (A), 2.4.7 Focus Visible (AA): one Tab stop, DOM order, the panel next.
- 2.5.8 Target Size (Minimum) (AA): a tab is at least 24 × 24 CSS px.
- 4.1.2 Name, Role, Value (A): roles, names,
aria-selected,aria-disabled.
Keyboard#
- Focus
- roving tabindex. The one Tab stop is the selected tab, or the tab that has focus while focus is in the list
- Selection follows focus
- yes, with
activationMode="automatic"(the default), except onto a disabled tab. No withactivationMode="manual": Enter or Space selects - Arrows wrap
- yes
- Shortcuts
- none
The tab list is one Tab stop. The selected tab has tabindex="0" and the others -1. While focus is in the list, the tab that has focus is the stop instead (the selected one when focus and selection agree), so Tab from a tab that is not selected leaves the list for the panel and does not move on to the selected tab. When focus leaves the list the selected tab is the stop again. The server render is already right: the selected tab 0, the others -1. Arrow keys flip in right-to-left text, read from the list's computed direction, so a dir on a container works without a provider. Tabs are ordered by their place in the page.
| Key | Where | What happens |
|---|---|---|
| Tab | before the list | Moves focus to the selected tab, the one Tab stop of the list Test: tabs.test.tsx › Tab enters at the selected tab |
| Tab | on a tab | Leaves the list for the selected panel, also from a tab that is not selected. A panel has tabindex="0". A panel that starts with a focusable element sets tabIndex={-1}, and Tab goes straight to that elementTest: tabs.test.tsx › Tab leaves the tab list for the panel |
| Shift+Tab | in the panel | Back to the selected tab, and the next Shift+Tab leaves the list Test: tabs.test.tsx › Shift+Tab returns to the selected tab and leaves the list |
| ArrowRight / ArrowLeft | tab list, horizontal | Next and previous tab, wrapping from the last to the first and back. Automatic activation selects the tab it moves to Test: tabs.test.tsx › ArrowRight and ArrowLeft move, wrap and select |
| ArrowLeft / ArrowRight | tab list, horizontal, right to left | The arrows flip: ArrowLeft is the next tab and ArrowRight the previous Test: tabs.test.tsx › right to left: the arrows flip |
| ArrowDown / ArrowUp | tab list, vertical | Next and previous tab, wrapping. They don't flip in right-to-left text. ArrowLeft and ArrowRight are not taken in a vertical list, and ArrowDown and ArrowUp are not taken in a horizontal one Test: tabs.test.tsx › vertical: ArrowDown and ArrowUp move |
| Home / End | tab list | First and last tab. Automatic activation selects it Test: tabs.test.tsx › Home and End go to the ends |
| Arrows, Enter, Space | manual activation | The arrows, Home and End move focus only: the selection stays where it was. Enter or Space on the focused tab selects it, through the native click Test: tabs.test.tsx › manual activation: arrows move focus, Enter and Space select |
| Arrows, Enter, Space | disabled tab | A disabled tab is reachable with the arrows and read as unavailable (aria-disabled). Automatic activation never selects it, so focus can be on a tab that is not selected. Enter, Space and a click do nothingTest: tabs.test.tsx › a disabled tab is reachable and never selected |
| (with a modifier key) | tab list | Not taken: Control+ArrowRight, Alt+ArrowRight, Shift+End and the like stay the browser's and the page's Test: tabs.test.tsx › keys with Control, Alt, Meta or Shift are left alone |
| (a key already handled) | tab | A key that a tab or your own handler already handled (defaultPrevented) is not taken againTest: tabs.test.tsx › a key that was already handled is not taken again |
Escape and the typed characters are not handled, and there is no typeahead (APG Tabs has none). A key from an element that isn't a tab is never the list's: a nested set of tabs in a panel keeps its own arrows (tabs.test.tsx › a nested Tabs keeps its own arrows).
Why these choices. Arrows wrap because APG's example does, and Home and End are implemented because they cost nothing. Automatic activation is the default, as APG advises when the panels show at once. Use activationMode="manual" when showing a panel is slow (it loads data, or is large): then arrowing through the tabs doesn't trigger it for each tab. Focus and selection can differ on a disabled tab in automatic mode, and in manual mode always: the contract says so, and the tab with focus is always the Tab stop while focus is in the list.
API reference#
import { Tabs, useTabs } from '@kvirn-ui/react'Tabs.Root
Renders <div> with no role: a plain container for the list and the panels. It owns the selected value, takes every attribute of a <div> and passes ref to it. The default theme is described on Theming.
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | – | Controlled: the value of the selected tab. Pair it with onValueChange and change it yourself. One of value and defaultValue is required. |
defaultValue | string | – | Uncontrolled: the value of the tab that is selected to begin with. There is no first-tab fallback. |
onValueChange | (value: string, details: TabsChangeDetails) => void | – | Called when the user selects a tab, with { reason: "press" | "arrow-key" | "home-end-key", event }. Never for a disabled tab or the tab that is already selected. |
activationMode | 'automatic' | 'manual' | 'automatic' | Automatic: the arrow keys, Home and End select the tab they move to. Manual: they only move focus, and Enter or Space selects. |
orientation | 'horizontal' | 'vertical' | 'horizontal' | The axis of the arrow keys: Left and Right (flipped in right-to-left text), or Down and Up when vertical. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-tabs | always | The part class. The default theme styles it. |
data-orientation | "horizontal" or "vertical" | The orientation. The default theme lays a vertical set out beside its panels. |
Tabs.List
Renders <div> with the role tablist. It owns the arrow keys, Home and End. Name it with aria-label or aria-labelledby.
| Class or attribute | Values | Meaning |
|---|---|---|
kv-tabs-list | always | The part class. |
aria-orientation | "vertical" or absent | Set only when vertical. Horizontal is the default of the tablist role. |
Tabs.Tab
Renders <button type="button"> with the role tab. Its name is its text.
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | Required | The tab’s value: ties it to the Tabs.Panel with the same value. |
disabled | boolean | false | Unavailable: aria-disabled="true", and it can’t be selected. The tab stays focusable so users can find it. Never a native disabled. |
onClick | MouseEventHandler<HTMLButtonElement> | – | Called after the tab is selected, and never while the tab is disabled. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-tabs-tab | always | The part class. |
aria-selected | "true" or "false" | Always set. Says which tab is selected. |
aria-disabled | "true" or absent | Set on a disabled tab. Not passed directly. |
data-selected | present or absent | The tab is selected. |
data-disabled | present or absent | The tab is disabled. |
Tabs.Panel
Renders <div> with the role tabpanel, named by its tab. Every panel is rendered, and the ones that aren’t selected are hidden.
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | Required | The value of the tab that shows this panel. |
tabIndex | number | 0 | Pass -1 when the panel starts with a focusable element, so Tab goes straight to it. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-tabs-panel | always | The part class. |
hidden | present or absent | Present while the panel isn’t selected. Every panel stays rendered. |
data-selected | present or absent | The panel is shown. |
useTabs
Options
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | – | Controlled: the value of the selected tab. Pair it with onValueChange and change it yourself. One of value and defaultValue is required. |
defaultValue | string | – | Uncontrolled: the value of the tab that is selected to begin with. There is no first-tab fallback. |
onValueChange | (value: string, details: TabsChangeDetails) => void | – | Called when the user selects a tab, with { reason: "press" | "arrow-key" | "home-end-key", event }. Never for a disabled tab or the tab that is already selected. |
activationMode | 'automatic' | 'manual' | 'automatic' | Automatic: the arrow keys, Home and End select the tab they move to. Manual: they only move focus, and Enter or Space selects. |
orientation | 'horizontal' | 'vertical' | 'horizontal' | The axis of the arrow keys: Left and Right (flipped in right-to-left text), or Down and Up when vertical. |
Result
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | – | The value of the selected tab. |
orientation | 'horizontal' | 'vertical' | – | The orientation in use. |
activationMode | 'automatic' | 'manual' | – | The activation mode in use. |
rootProps | TabsRootPartProps | – | Spread on the root <div>: class and data-orientation. |
listProps | TabsListPartProps | – | Spread on the list <div>: class, role, the keys and the blur handler. |
getTabProps | (value: string, options?: { disabled?: boolean; onClick?: MouseEventHandler }) => TabsTabPartProps | – | The props of one <button>: id, role, tabindex, aria-selected, aria-controls, handlers and a ref. |
getPanelProps | (value: string) => TabsPanelPartProps | – | The props of one <div>: id, role, tabindex, aria-labelledby, hidden and a ref. |
Known issues#
- Focus and selection can differ. A disabled tab takes focus and is not selected in automatic mode, and in manual mode focus moves without selecting. The tab with focus is the Tab stop while focus is in the list, so Tab always leaves the list for the panel.
- One redundant Tab stop on a panel whose first content is focusable, unless the consumer passes
tabIndex={-1}. - Hidden panels still mount. Every panel is rendered with
hidden: a heavy panel should render its children only while its tab is selected, using your ownvalue. - A tab that unmounts while it has focus leaves no Tab stop in the list until focus moves. Closable tabs are not supported.
- Before hydration the tabs are already right (the selected tab
0, the others-1, every panel rendered), but the arrow keys need JavaScript.
Testing#
The automated tests prove the keyboard behaviour, the names and states, that axe finds no violations in every story and theme, and, for the components they cover, that the stories hold up in forced colours, reduced motion, text spacing and a 320 pixel width. An Automated row passes on these tests alone. A Core or Release row passes only when an automated agent check and a person on the real assistive technology have both checked it. "agent-verified" means automated tests in the repository (with a virtual screen reader for the screen reader rows), not the real assistive technology.
| AT + browser + OS | Agent check | Human check | Result | Notes |
|---|---|---|---|---|
| Automated (re-runnable tests) | ||||
| axe, WCAG 2.2 A and AA, every story, 4 themes | pass | n/a | pass | tabs.stories.tsx, every story, 4 themes |
| Markup and ARIA (roles, names, ids, states) | pass | n/a | pass | tabs.test.tsx › is a tablist of tabs and panels with the names the consumer gives, and warns about nothing; expectNoA11yViolations |
| Keyboard contract rows (Vitest browser) | pass | n/a | pass | 11 rows, each names a test (tabs.test.tsx › Tab enters at the selected tab) |
| Focus order and management | pass | n/a | pass | tabs.test.tsx asserts focus (toHaveFocus); first rule: Tab enters at the selected tab |
| Display modes (forced colours, 320px reflow, text spacing, reduced motion) | pass | n/a | pass | the four sweep projects (storybook-forced-colors, -reduced-motion, -reflow, -text-spacing), run in CI |
| Core (required for beta) | ||||
| NVDA + Chrome + Windows | pending | pending | pending | |
| VoiceOver + Safari + iOS | pending | pending | pending | |
| Release (before 1.0 and each minor) | ||||
| JAWS + Chrome + Windows | pending | pending | pending | |
| TalkBack + Chrome + Android | pending | pending | pending | |
| VoiceOver + Safari + macOS | pending | pending | pending |
What to check#
With a screen reader and the keyboard, try:
- Tab into the list: focus lands on the selected tab.
- Right and Left move between the tabs, wrap, and change the panel.
- Tab from a tab goes to the panel.
- With
activationMode="manual"the arrows move focus and Enter selects. - A disabled tab is reached and read as unavailable.