Navigation
Tabs
Switches between panels on the same page without changing the URL, e.g. Preview and Code.
- Experimental
- Keyboard tested
- Screen reader not tested yet
Playground
Change the props and the surface. The controls come from the documented props; the surfaces are the real modes.
Preview panel.
<Tabs
label="Playground tabs"
items={[
{
id: "preview",
label: "Preview",
content: <p className="text-secondary">Preview panel.</p>,
},
{
id: "code",
label: "Code",
content: <p className="text-secondary">Code panel.</p>,
},
]}
/>Usage
When to use
Use tabs to switch between panels of the same content on one page, without changing the URL: Preview and Code, for example.
When not to use
- For subpages with their own URL: use TabNav.
- When people need to see both panels at once: show them one after the other.
How it works
An ARIA tablist: only the selected tab is in the Tab order, the arrow keys move between tabs, and the panel follows. The selected tab is marked with an underline.
Content guidelines
Two to five short labels, one or two words each.
Do and don’t
Do
- Two to five short tab labels.
Don’t
- Don't use Tabs for subpages with their own URL; use TabNav.
Anatomy
The parts of the component and what each one does, as in the playground above.
- tab14px medium; selected tab in text.primary with a 2px accent line.
- indicator2px accent line under the selected tab.
- panelContent of the selected tab.
Examples
Type-checked, and the same code goes into the AI manifest. Import: import { Tabs } from "@/ds";
Two panels
Preview panel.
Props
Checked against the component's TypeScript type on every build.
| Name | Type | Default | Description |
|---|---|---|---|
| label (required) | string | – | Accessible name of the tab list. |
| items (required) | TabItem[] | – | id, label and content per tab. |
| defaultSelected | string | – | id of the tab selected first. |
Tokens used
Derived from the utility classes in the component's source. Copy a class with one click.
| Token | Tier | Value | Utility |
|---|---|---|---|
| button.radius | component | 9999px | |
| tabs.border | component | rgba(10,10,11,0.08) | |
| tabs.fg | component | #555555 | |
| tabs.fgHover | component | #0A0A0B | |
| tabs.fgSelected | component | #0A0A0B | |
| tabs.indicator | component | #C6492E | |
| focus | semantic | #C6492E | |
| spacing.0 | semantic | 0px | |
| spacing.3 | semantic | 12px | |
| spacing.6 | semantic | 24px | |
| surface.page | semantic | #FAFAF7 | |
| text.secondary | semantic | #555555 | |
| type.small.size | semantic | 14px | |
| weight.medium | semantic | 500 |
Accessibility
What is checked automatically on every build, and what a person has tested. Nothing is marked as tested unless it was.
| Check | How | Status |
|---|---|---|
| axe-core rules | Automated on every npm run check, at desktop and mobile width | Runs on every build |
| Keyboard | Automated Playwright test (scripts/keyboard.mjs) | Tested |
| Screen reader | Manual | Not tested yet |
Keyboard
| Key | Action |
|---|---|
| Tab | Moves into the tab list, then into the panel. |
| Arrow left / right | Selects the previous or next tab. |
| Home / End | Selects the first or last tab. |
Semantics and focus
- role="tablist", "tab" and "tabpanel" with aria-selected and aria-controls, from React Aria.
- Only the selected tab is in the Tab order; arrow keys move between tabs.
Contrast
| Pairing | Ratio (x:1) | Minimum | Status |
|---|---|---|---|
| text.primary on surface.page | 18.92 | 4.5 | Pass |
| text.secondary on surface.page | 7.13 | 4.5 | Pass |
| accent.default on surface.page | 4.57 | 4.5 | Pass |
| focus on surface.page | 4.57 | 3.0 | Pass |