<!-- index: /slotted/llms.txt -->
# tabs

`data-ui="tabs"` · Switches between panels of related content.

## Import

```tsx
import { Tab, TabActions, TabList, TabPanel, Tabs, TabsDefaultsProvider } from '@slotted/react';
```

## Minimal example

Example

```tsx
import {
  DescriptionList,
  DescriptionListDescription,
  DescriptionListItem,
  DescriptionListTerm,
} from '@slotted/react/description-list';
import { Stack } from '@slotted/react/stack';
import { Tab, TabList, TabPanel, Tabs } from '@slotted/react/tabs';
import { Text } from '@slotted/react/typography';

const SECTIONS = [
  {
    value: 'summary',
    label: 'Summary',
    pairs: [
      ['Customer', 'Harbor & Pine'],
      ['Placed', 'September 8, 2026'],
      ['Payment terms', 'Net 30'],
      ['Total', '$1,240.00'],
    ],
  },
  {
    value: 'items',
    label: 'Items',
    pairs: [
      ['Oak shelf, 90 cm', '4 × $180.00'],
      ['Wall bracket, steel', '8 × $24.00'],
      ['Assembly kit', '1 × $328.00'],
    ],
  },
  {
    value: 'shipments',
    label: 'Shipments',
    pairs: [
      ['Carrier', 'Atlas Freight'],
      ['Tracking', 'AF-2210-4471'],
      ['Expected', 'September 12, 2026'],
    ],
  },
];

const ACTIVITY = [
  'Sep 9, 14:02 — Picked at Reno, NV',
  'Sep 8, 16:45 — Payment approved',
  'Sep 8, 16:41 — Order placed by Dana Whitfield',
];

export default function TabsBasic() {
  return (
    <Tabs defaultValue="summary">
      <TabList aria-label="Order SO-1187">
        {SECTIONS.map((section) => (
          <Tab key={section.value} value={section.value}>
            {section.label}
          </Tab>
        ))}
        <Tab value="activity">Activity</Tab>
      </TabList>
      {SECTIONS.map((section) => (
        <TabPanel key={section.value} value={section.value}>
          <DescriptionList>
            {section.pairs.map(([term, description]) => (
              <DescriptionListItem key={term}>
                <DescriptionListTerm>{term}</DescriptionListTerm>
                <DescriptionListDescription>{description}</DescriptionListDescription>
              </DescriptionListItem>
            ))}
          </DescriptionList>
        </TabPanel>
      ))}
      <TabPanel value="activity">
        <Stack gap={2}>
          {ACTIVITY.map((entry) => (
            <Text key={entry} size="sm">
              {entry}
            </Text>
          ))}
        </Stack>
      </TabPanel>
    </Tabs>
  );
}
```

## Anatomy

| Part | Element | Required |
| --- | --- | --- |
| `root` | div, or the element render returns | yes |
| `list` | div[role="tablist"], or the element render returns | yes |
| `item` | div[role="presentation"], or the element the render of Tab returns | yes |
| `tab` | button[role="tab"], or a[role="tab"] with href | yes |
| `start` | span | no |
| `label` | span | yes |
| `end` | span | no |
| `dismiss` | button | no |
| `marker` | span, aria-hidden | no |
| `panel` | div[role="tabpanel"] | yes |
| `scroll` | button | no |
| `actions` | div, or the element render returns | no |

## Props

| Name | Type | Default | Applies to | Description |
| --- | --- | --- | --- | --- |
| `value` | `string` | — | Tabs | The value of the selected tab. Passing it makes the selection controlled for the life of the component; without it, Tabs keeps the selection and starts from defaultValue. |
| `defaultValue` | `string` | — | Tabs | The value an uncontrolled Tabs starts from, read once. When it is unset, no tab is selected and no panel is shown. |
| `activation` | `'automatic' \| 'manual'` | automatic | Tabs, TabsDefaultsProvider | Whether moving focus to a tab also selects it. The APG recommends automatic when panels show without a noticeable delay, and manual when a panel has to be fetched. |
| `orientation` | `'horizontal' \| 'vertical'` | horizontal | Tabs, TabsDefaultsProvider | Which way the list runs, and so which arrow keys move between tabs. A horizontal list ignores Up and Down, so those keys keep scrolling the page. |
| `size` | `'sm' \| 'md' \| 'lg'` | md | Tabs, TabsDefaultsProvider | The control step of the list: height, type, padding and inner gap, all from the control scales the theme restates per density. |
| `variant` | `'line' \| 'contained'` | line | Tabs, TabsDefaultsProvider | How the list is drawn. Both variants paint the accent marker, which keeps the selected tab visible in the high-contrast scheme, where every surface is flattened. |
| `track` | `'line' \| 'none'` | line | Tabs, TabsDefaultsProvider | Whether the list draws the line its tabs stand on. none is for a list placed on a line the page already draws, such as a card header’s edge or a table’s rule, where two hairlines a pixel apart read as one smudge. The marker then sits on the item’s own edge, on the line that is there. |
| `fit` | `'auto' \| 'equal'` | auto | Tabs, TabsDefaultsProvider | Whether each tab is as wide as its label or takes an equal share of the line. equal cuts a label longer than its share with an ellipsis; auto never cuts a label and scrolls the list instead. |
| `mount` | `'active' \| 'lazy' \| 'eager'` | active | Tabs, TabsDefaultsProvider | When a panel’s content exists: only while its tab is selected (active), from its first selection on (lazy), or from the start (eager). A panel that is not selected carries the hidden attribute. |
| `deferPanels` | `boolean` | true under mount="active", false otherwise | Tabs | Whether the panels render from useDeferredValue(value). The selected tab paints in the click’s frame and its panel renders after it; until it is ready the panel on screen stays, with aria-busy and data-pending. A panel that suspends keeps the shown one when its Suspense boundary is outside Tabs; a boundary inside the new panel shows its own fallback. |
| `loop` | `boolean` | true | Tabs, TabsDefaultsProvider | Whether the arrow keys wrap past the ends of the list. |
| `disabled` | `boolean` | false | Tabs | Disables every tab with the native attribute, which also makes the arrow keys skip them, and dims the track. |
| `value, on Tab` | `string` | — | Tab | What this tab selects, and what the value of Tabs holds. It reaches the DOM as data-value, which the keyboard reads. |
| `disabled, on Tab` | `boolean` | from Tabs, or false | Tab | Disables this tab only, so one tab can be unavailable in a working list. Unset rather than false, so the tab follows Tabs. |
| `dismissible` | `boolean` | false | Tab | Draws the close button and binds Delete on the tab, announced through aria-keyshortcuts. |
| `dismissLabel` | `string` | — | Tab | The accessible name of the close button, required whenever it is drawn. Name what closes: “Close customers.sql” rather than “Close”. |
| `start` | `ReactNode` | — | Tab | Content before the label, such as an Icon, placed in the start part beside the words. |
| `end` | `ReactNode` | — | Tab | Content after the label, such as a Badge with a count, placed in the end part beside the words. |
| `controls` | `string` | — | Tab | The id of the region this tab controls when it is not a TabPanel, such as a table the selected value filters. aria-controls names that region. |
| `href` | `string` | — | Tab | Renders the tab as a link. A plain click selects the tab without navigating; a click with a modifier key is left to the browser, which opens the address in a new browser tab or window. |
| `value, on TabPanel` | `string` | — | TabPanel | The tab this panel belongs to. Tabs wires the pair with ids generated from the value. |
| `render` | `(props) => ReactNode` | — | Tabs, TabList, Tab, TabPanel, TabActions | Replaces the root element of any of the five and passes it every attribute, so a list can be a nav and Tabs a section. The tab control itself cannot be replaced: it holds the role, the value and the keyboard, and href covers the substitution that matters. |
| `ref` | `Ref<HTMLElement>` | — | Tab, TabPanel, Tabs | On Tab, reaches the tab’s own control, so focus() and click() are the element’s own methods and no imperative handle stands in for them. |
| `useTabs()` | `() => TabsContextValue` | — | inside Tabs | What a tab and a panel read: the value, shownValue (the value the panels render, deferred under deferPanels), the mount strategy, the ids, and select(value, reason, source) for a view the page changes on its own. A region rendered outside the panels — a page header’s tab with controls= — renders from shownValue. It throws outside Tabs instead of rendering a control that looks right and does nothing. |
| `TabsDefaultsProvider` | `{ activation, orientation, size, variant, track, fit, mount, loop }` | — | a subtree | The eight settings an application decides once. A value set on one Tabs still wins. |
| `aria-label, on TabList` | `string` | — | TabList | The name of the set of views. Tabs writes no name of its own; aria-labelledby works the same way. |

## Events

| Name | Payload | When |
| --- | --- | --- |
| `onValueChange` | `(value: string, request: ChangeRequest<string \| undefined>)` | Before the selection moves. The request carries the new value, the previous value (undefined while no tab is selected), the reason (pointer, keyboard, remove or programmatic), the originating event, and cancel(), which keeps the current tab. |
| `onTabDismiss` | `(value: string, request: TabsDismissRequest)` | Before a tab is closed, by Delete or by its close button. The request carries the reason (pointer or keyboard) and cancel(), which stops both the dismissal and the selection move that would follow it. Tabs removes nothing itself: remove the tab from your own data. |
| `onClick, onKeyDown, onFocus, on each Tab` | `the element’s own events` | When the tab’s control fires them. Your handler runs first, and preventDefault() in onClick also stops the selection. |

## Axes and defaults

| Axis | Values | Default |
| --- | --- | --- |
| `activation` | `automatic`, `manual` | `automatic` |
| `orientation` | `horizontal`, `vertical` | `horizontal` |
| `size` | `sm`, `md`, `lg` | `md` |
| `variant` | `line`, `contained` | `line` |
| `track` | `line`, `none` | `line` |
| `fit` | `auto`, `equal` | `auto` |
| `mount` | `active`, `lazy`, `eager` | `active` |

## Rules

- Selecting a tab never waits for its panel: keep value urgent and render the region from useDeferredValue(value), which deferPanels does for the panels and useTabs().shownValue hands a region outside them. Wrapping the setter in startTransition delays the marker too.
- Tabs implements the WAI-ARIA APG Tabs pattern (w3.org/WAI/ARIA/apg/patterns/tabs/) and its whole keyboard table: Tab enters the list on the selected tab and leaves to the panel, the arrow keys of the list’s direction move focus and wrap at both ends, Home and End reach the first and last enabled tab, Enter and Space select under manual activation, and Delete closes a dismissible tab. A horizontal list does not listen for Up and Down, so those keys keep scrolling the page while focus is in the list.
- After a dismissal, focus follows the pattern: the next tab, the previous one when the closed tab was last, or the list itself when no tab is left, which is why the list carries tabindex="-1". The selection follows the same rule, with the reason remove.
- The close button is outside the arrow-key sequence and inside the accessibility tree. A screen reader reaches and presses it; from the keyboard, Delete closes the focused tab, and the tab announces the key with aria-keyshortcuts. In the arrow-key sequence, close buttons would double the presses it takes to cross the list.
- The paging controls are aria-hidden and outside the Tab sequence, because the arrow keys reach every tab and scroll it into view. Cloudscape’s guidance warns against extra Tab stops between a tab list and its panel.
- A list that starts to overflow scrolls the selected tab into view once its paging controls are drawn, so the selected tab is not left behind the end control.
- Each tab names its panel with aria-controls and each panel names its tab with aria-labelledby. The ids come from the value, with the characters an id cannot hold escaped rather than replaced, so two values that differ only by a space never share a panel.
- The selected tab is never shown by color alone: the marker is a bar never thinner than a thick border, which stays visible in the high-contrast scheme, where the theme paints every surface Canvas and the fill of the contained variant disappears.
- A panel carries tabindex="0", so the Tab key reaches it from the list. The pattern permits that stop even when the panel’s first content is focusable.

## Tokens

`--slotted-border-strong`, `--slotted-border-subtle`, `--slotted-border-width-thick`, `--slotted-border-width-thin`, `--slotted-control-font-family`, `--slotted-control-font-size-lg`, `--slotted-control-font-size-md`, `--slotted-control-font-size-sm`, `--slotted-control-font-weight`, `--slotted-control-gap-lg`, `--slotted-control-gap-md`, `--slotted-control-gap-sm`, `--slotted-control-height-lg`, `--slotted-control-height-md`, `--slotted-control-height-sm`, `--slotted-control-icon-size-lg`, `--slotted-control-icon-size-md`, `--slotted-control-icon-size-sm`, `--slotted-control-inner-size-lg`, `--slotted-control-inner-size-md`, `--slotted-control-inner-size-sm`, `--slotted-control-letter-spacing`, `--slotted-control-line-height`, `--slotted-control-padding-inline-lg`, `--slotted-control-padding-inline-md`, `--slotted-control-padding-inline-sm`, `--slotted-control-radius`, `--slotted-control-transition-duration`, `--slotted-control-transition-easing`, `--slotted-disabled-background`, `--slotted-disabled-border`, `--slotted-disabled-foreground`, `--slotted-duration-medium`, `--slotted-duration-short`, `--slotted-easing-enter`, `--slotted-focus-ring-color`, `--slotted-focus-ring-offset`, `--slotted-focus-ring-width`, `--slotted-radius-full`, `--slotted-radius-md`, `--slotted-radius-sm`, `--slotted-shadow-xs`, `--slotted-space-1`, `--slotted-space-2`, `--slotted-space-4`, `--slotted-space-6`, `--slotted-surface`, `--slotted-surface-sunken`, `--slotted-tabs-actions-gap`, `--slotted-tabs-active-background`, `--slotted-tabs-active-marker-color`, `--slotted-tabs-color`, `--slotted-tabs-contained-background`, `--slotted-tabs-contained-selected-background`, `--slotted-tabs-dismiss-active-background`, `--slotted-tabs-dismiss-active-color`, `--slotted-tabs-dismiss-color`, `--slotted-tabs-dismiss-hover-background`, `--slotted-tabs-dismiss-hover-color`, `--slotted-tabs-fade-size`, `--slotted-tabs-gap`, `--slotted-tabs-hover-background`, `--slotted-tabs-hover-color`, `--slotted-tabs-hover-marker-color`, `--slotted-tabs-hover-marker-opacity`, `--slotted-tabs-list-gap`, `--slotted-tabs-marker-color`, `--slotted-tabs-marker-easing`, `--slotted-tabs-marker-inset`, `--slotted-tabs-marker-offset`, `--slotted-tabs-marker-radius`, `--slotted-tabs-marker-size`, `--slotted-tabs-scroll-color`, `--slotted-tabs-selected-color`, `--slotted-tabs-track-color`, `--slotted-target-comfortable`, `--slotted-target-min`, `--slotted-text`, `--slotted-text-muted`, `--slotted-tone-accent-solid`, `--slotted-tone-accent-text`, `--slotted-tone-secondary-subtle-active`, `--slotted-tone-secondary-subtle-hover`

## Examples

See [tabs.examples.md](./tabs.examples.md).
