Skip to content

Components · Navigation

note:Copy source: not an npm package.

AccessibleTabs

WAI-ARIA tabs with roving focus, arrow/Home/End keys, disabled tabs and optional manual activation.

  • aria
  • keyboard
  • roving tabindex
Dependencies
None beyond React
Source
src/components/collection/accessible-tabs/accessible-tabs.tsx

Preview & code

Options

Selected: overview

A browser-based code notebook that keeps the reason next to each snippet.

Try it with the keyboard: Tab into the tabs, then use ←/→, Home and End. With manual activation, arrows move focus and Enter or Space selects.

When to use it

Switching between related views (preview and code, overview and details) without leaving the page, while behaving the way keyboard and screen-reader users expect tabs to behave.

Usage

  1. Copy src/components/collection/accessible-tabs/accessible-tabs.tsx into your project (from the Code tab above).
  2. Import it from where you placed it. In this repo that’s @/components/collection/accessible-tabs/accessible-tabs.
usage.tsxtsx
import { AccessibleTabs } from "@/components/collection/accessible-tabs/accessible-tabs";​export function ProjectTabs() {  return (    <AccessibleTabs      label="Project details"      items={[        { id: "overview", label: "Overview", content: <p>What it does.</p> },        { id: "stack", label: "Stack", content: <p>React, Vite, Tailwind CSS.</p> },      ]}    />  );}

API

AccessibleTabs props
PropTypeDefaultDescription
items* (required)TabItem[]—Tabs as { id, label, content, disabled? }. Ids must be unique.
label* (required)string—Accessible name for the tab list.
valuestring—Selected id when controlled.
defaultValuestringfirst enabled tabInitial selection when uncontrolled.
onValueChange(id: string) => void—Called when the selection changes.
activation"automatic" | "manual""automatic"Select on arrow focus, or wait for Enter/Space.
classNamestring—Classes on the wrapper.
panelClassNamestring—Classes on every panel.

* required

Accessibility

Tab
Moves focus into the tab list (selected tab), then into the active panel.
← / →
Moves to the previous/next enabled tab, wrapping at the ends.
Home / End
Moves to the first/last enabled tab.
Enter / Space
Selects the focused tab (needed with manual activation).
  • Uses role="tablist", "tab" and "tabpanel" with aria-selected, aria-controls and aria-labelledby wired by generated ids.
  • Only the selected tab is in the Tab order (roving tabindex); panels are focusable so their content is reachable.
  • Disabled tabs are skipped by arrow keys and exposed as disabled.
  • Inactive panels use the hidden attribute, so they are removed from the accessibility tree but keep their state.

Limits & tests

Limitations

  • Horizontal orientation only.
  • All panels are mounted; for very heavy panels, render content lazily inside the panel yourself.
  • No overflow menu: many tabs scroll horizontally.

Tests

tests/e2e/components.spec.ts

  • Arrow, Home and End keys move focus and selection with correct ARIA state
  • Manual activation moves focus without selecting until Enter
  • Disabled tabs are skipped
  • Used for the Preview/Code switch on every component page