# Tabs

Switches between panels of related content in place. Two looks: underline, a bar under the selected tab on a baseline across the row, and segmented, a raised segment in a recessed sunken track. Each tab shows text, an icon and text, or only an icon.

**Dependencies:** npm: 2 direct, 3 total; registry: 2 direct, 2 total.

Native: iOS stable, Android stable.

## Usage

### When to use

- Split one page or card into a few sections the user switches between in place: Overview, Activity, Settings.
- Switch between views of the same content in a small space, such as files as a grid or a list, with the segmented look.
- A segmented control across a phone screen, every tab an equal share, with fullWidth.

### When not to use

- Going to another page. Use a link; tabs swap panels in place.
- Running an action, such as saving or exporting. Use Button.
- Picking a value for a form field. Use Select.
- The steps of a flow that must be done in order.

### Native

**Default**

```text
WerewolfTabs(value: tab, onValueChange: { tab = $0 }) {
    WerewolfTabsTrigger(value: "overview", label: AnyView(Text("Overview")))
    WerewolfTabsTrigger(value: "activity", label: AnyView(Text("Activity")))
} content: {
    Text(tab)
}
```

```text
WerewolfTabs(value = tab, onValueChange = { tab = it }, list = {
    WerewolfTabsTrigger(value = "overview", label = { Text("Overview") })
    WerewolfTabsTrigger(value = "activity", label = { Text("Activity") })
}) {
    Text(tab)
}
```

**With icons**

```text
WerewolfTabs(defaultValue: "overview", variant: .segmented) {
    WerewolfTabsTrigger(value: "overview", icon: AnyView(Image(systemName: "house")), label: AnyView(Text("Overview")))
    WerewolfTabsTrigger(value: "settings", icon: AnyView(Image(systemName: "gear")), label: AnyView(Text("Settings")))
} content: {
    Text("Panel")
}
```

```text
WerewolfTabs(defaultValue = "overview", variant = WerewolfTabsVariant.Segmented, list = {
    WerewolfTabsTrigger(value = "overview", icon = { Icon(homeIcon, contentDescription = null) }, label = { Text("Overview") })
    WerewolfTabsTrigger(value = "settings", icon = { Icon(gearIcon, contentDescription = null) }, label = { Text("Settings") })
}) {
    Text("Panel")
}
```

**Disabled tab**

```text
WerewolfTabs(defaultValue: "overview") {
    WerewolfTabsTrigger(value: "overview", label: AnyView(Text("Overview")))
    WerewolfTabsTrigger(value: "billing", label: AnyView(Text("Billing")))
        .disabled(true)
} content: {
    Text("Panel")
}
```

```text
WerewolfTabs(defaultValue = "overview", list = {
    WerewolfTabsTrigger(value = "overview", label = { Text("Overview") })
    WerewolfTabsTrigger(value = "billing", label = { Text("Billing") }, enabled = false)
}) {
    Text("Panel")
}
```

## Variants

### variant

Set on TabsList. underline: sections of a page or a card. segmented: switching views of the same content in a small space, such as Grid and List, or a filter next to other controls.

Values: `underline`, `segmented`. Default: `underline`.

### size

Set on TabsList. List height from size-element-*: sm 28px, md 32px (the default), lg 36px, xl 44px with a mouse; on touch md is 36px, lg 44px and xl 48px. Match the Button or Input next to it; use lg or xl for the main sections of a screen on touch.

Values: `sm`, `md`, `lg`, `xl`. Default: `md`.

### orientation

Set on Tabs. vertical stacks the tabs in a column at the start with the panel beside it, for a settings page with sections. Up and Down arrows move between tabs instead of Left and Right. The underline bar moves to the end edge.

Values: `horizontal`, `vertical`. Default: `horizontal`.

### activationMode

Set on Tabs. automatic shows a panel as soon as its tab gets focus. manual waits for Enter or Space: use it when a panel is slow to render, so arrowing past tabs does not load each one.

Values: `automatic`, `manual`. Default: `automatic`.

## Examples

### Default

Underline tabs for the sections of a page.

```tsx
<Tabs defaultValue="overview" className="w-full min-w-0 max-w-full">
  <TabsList className="h-auto max-w-full flex-wrap gap-y-[max(var(--spacing-xs),calc(var(--size-target-min)-var(--size-element-md)+var(--spacing-xs)+var(--border-width)))]">
    <TabsTrigger value="overview" className="h-[calc(var(--size-element-md)-var(--spacing-xs)-var(--border-width))] min-w-max">Overview</TabsTrigger>
    <TabsTrigger value="activity" className="h-[calc(var(--size-element-md)-var(--spacing-xs)-var(--border-width))] min-w-max">Activity</TabsTrigger>
    <TabsTrigger value="settings" className="h-[calc(var(--size-element-md)-var(--spacing-xs)-var(--border-width))] min-w-max">Settings</TabsTrigger>
  </TabsList>
  <TabsContent value="overview" className="text-sm text-text-secondary">Tokens, components and docs for this project.</TabsContent>
  <TabsContent value="activity" className="text-sm text-text-secondary">Changes from your team in the last 30 days.</TabsContent>
  <TabsContent value="settings" className="text-sm text-text-secondary">Name, members and access.</TabsContent>
</Tabs>
```

### With icons

An icon before every label, never on only some tabs.

```tsx
<Tabs defaultValue="overview" className="w-full min-w-0 max-w-full">
  <TabsList className="h-auto max-w-full flex-wrap gap-y-[max(var(--spacing-xs),calc(var(--size-target-min)-var(--size-element-md)+var(--spacing-xs)+var(--border-width)))]">
    <TabsTrigger value="overview" className="h-[calc(var(--size-element-md)-var(--spacing-xs)-var(--border-width))] min-w-max">
      <IconHome size={16} />
      Overview
    </TabsTrigger>
    <TabsTrigger value="activity" className="h-[calc(var(--size-element-md)-var(--spacing-xs)-var(--border-width))] min-w-max">
      <IconChartLine size={16} />
      Activity
    </TabsTrigger>
    <TabsTrigger value="settings" className="h-[calc(var(--size-element-md)-var(--spacing-xs)-var(--border-width))] min-w-max">
      <IconSettings size={16} />
      Settings
    </TabsTrigger>
  </TabsList>
  <TabsContent value="overview" className="text-sm text-text-secondary">Tokens, components and docs for this project.</TabsContent>
  <TabsContent value="activity" className="text-sm text-text-secondary">Changes from your team in the last 30 days.</TabsContent>
  <TabsContent value="settings" className="text-sm text-text-secondary">Name, members and access.</TabsContent>
</Tabs>
```

### Icon only

A segmented view switcher. Each tab names its view in aria-label.

```tsx
<Tabs defaultValue="grid" className="min-w-0 max-w-full">
  <TabsList variant="segmented" className="h-auto max-w-full flex-wrap gap-y-[max(var(--spacing-xs),calc(var(--size-target-min)-var(--size-element-md)+2*var(--spacing-xs)+2*var(--border-width)))]">
    <TabsTrigger value="grid" iconOnly aria-label="Grid" className="h-[calc(var(--size-element-md)-2*var(--spacing-xs)-2*var(--border-width))] min-w-max">
      <IconLayoutGrid size={16} />
    </TabsTrigger>
    <TabsTrigger value="list" iconOnly aria-label="List" className="h-[calc(var(--size-element-md)-2*var(--spacing-xs)-2*var(--border-width))] min-w-max">
      <IconList size={16} />
    </TabsTrigger>
  </TabsList>
  <TabsContent value="grid" className="text-sm text-text-secondary">Files as a grid of thumbnails.</TabsContent>
  <TabsContent value="list" className="text-sm text-text-secondary">Files as a list with size and date.</TabsContent>
</Tabs>
```

### Full width

Segmented tabs that share the width of a narrow screen equally.

```tsx
<Tabs defaultValue="week" className="w-full min-w-0 max-w-full">
  <TabsList variant="segmented" fullWidth className="h-auto max-w-full flex-wrap gap-y-[max(var(--spacing-xs),calc(var(--size-target-min)-var(--size-element-md)+2*var(--spacing-xs)+2*var(--border-width)))]">
    <TabsTrigger value="day" className="h-[calc(var(--size-element-md)-2*var(--spacing-xs)-2*var(--border-width))] min-w-max">Day</TabsTrigger>
    <TabsTrigger value="week" className="h-[calc(var(--size-element-md)-2*var(--spacing-xs)-2*var(--border-width))] min-w-max">Week</TabsTrigger>
    <TabsTrigger value="month" className="h-[calc(var(--size-element-md)-2*var(--spacing-xs)-2*var(--border-width))] min-w-max">Month</TabsTrigger>
  </TabsList>
  <TabsContent value="day" className="text-sm text-text-secondary">Changes from today.</TabsContent>
  <TabsContent value="week" className="text-sm text-text-secondary">Changes from the last 7 days.</TabsContent>
  <TabsContent value="month" className="text-sm text-text-secondary">Changes from the last 30 days.</TabsContent>
</Tabs>
```

### Disabled tab

Stays in the row but can't be selected; arrow keys skip it.

```tsx
<Tabs defaultValue="overview" className="w-full min-w-0 max-w-full">
  <TabsList className="h-auto max-w-full flex-wrap gap-y-[max(var(--spacing-xs),calc(var(--size-target-min)-var(--size-element-md)+var(--spacing-xs)+var(--border-width)))]">
    <TabsTrigger value="overview" className="h-[calc(var(--size-element-md)-var(--spacing-xs)-var(--border-width))] min-w-max">Overview</TabsTrigger>
    <TabsTrigger value="activity" className="h-[calc(var(--size-element-md)-var(--spacing-xs)-var(--border-width))] min-w-max">Activity</TabsTrigger>
    <TabsTrigger value="billing" disabled className="h-[calc(var(--size-element-md)-var(--spacing-xs)-var(--border-width))] min-w-max">Billing</TabsTrigger>
  </TabsList>
  <TabsContent value="overview" className="text-sm text-text-secondary">Tokens, components and docs for this project.</TabsContent>
  <TabsContent value="activity" className="text-sm text-text-secondary">Changes from your team in the last 30 days.</TabsContent>
  <TabsContent value="billing" className="text-sm text-text-secondary">Plan and invoices.</TabsContent>
</Tabs>
```

### Next tab loading

The user picked Activity, which is still loading: Overview stays on screen, dimmed and marked busy. In an app, pending is the isPending of the transition that changes the tab.

```tsx
<Tabs defaultValue="overview" className="w-80 min-w-0 max-w-full">
  <TabsList className="h-auto max-w-full flex-wrap gap-y-[max(var(--spacing-xs),calc(var(--size-target-min)-var(--size-element-md)+var(--spacing-xs)+var(--border-width)))]">
    <TabsTrigger value="overview" className="h-[calc(var(--size-element-md)-var(--spacing-xs)-var(--border-width))] min-w-max">Overview</TabsTrigger>
    <TabsTrigger value="activity" className="h-[calc(var(--size-element-md)-var(--spacing-xs)-var(--border-width))] min-w-max">Activity</TabsTrigger>
  </TabsList>
  <TabsContent value="overview" pending pendingLabel="Loading activity" className="text-sm text-text-secondary">Revenue is up 12% this month.</TabsContent>
  <TabsContent value="activity" className="text-sm text-text-secondary">3 new comments.</TabsContent>
</Tabs>
```

### Vertical

```tsx
<Tabs defaultValue="profile" orientation="vertical" className="w-full min-w-0 max-w-full">
  <TabsList aria-label="Settings" className="h-auto max-w-full flex-wrap gap-y-[max(var(--spacing-xs),calc(var(--size-target-min)-var(--size-element-md)+var(--spacing-xs)+var(--border-width)))]">
    <TabsTrigger value="profile" className="h-[calc(var(--size-element-md)-var(--spacing-xs)-var(--border-width))] min-w-max">Profile</TabsTrigger>
    <TabsTrigger value="notifications" className="h-[calc(var(--size-element-md)-var(--spacing-xs)-var(--border-width))] min-w-max">Notifications</TabsTrigger>
    <TabsTrigger value="billing" className="h-[calc(var(--size-element-md)-var(--spacing-xs)-var(--border-width))] min-w-max">Billing</TabsTrigger>
  </TabsList>
  <TabsContent value="profile" className="text-sm text-text-secondary">Name, photo and bio.</TabsContent>
  <TabsContent value="notifications" className="text-sm text-text-secondary">Email and push alerts.</TabsContent>
  <TabsContent value="billing" className="text-sm text-text-secondary">Plan and invoices.</TabsContent>
</Tabs>
```

### With a count

A Badge after the label. The count is part of the tab name, so it is read out with it.

```tsx
<Tabs defaultValue="open" className="w-full min-w-0 max-w-full">
  <TabsList aria-label="Issues" className="h-auto max-w-full flex-wrap gap-y-[max(var(--spacing-xs),calc(var(--size-target-min)-var(--size-element-md)+var(--spacing-xs)+var(--border-width)))]">
    <TabsTrigger value="open" className="h-[calc(var(--size-element-md)-var(--spacing-xs)-var(--border-width))] min-w-max">
      Open
      <Badge size="sm">12</Badge>
    </TabsTrigger>
    <TabsTrigger value="closed" className="h-[calc(var(--size-element-md)-var(--spacing-xs)-var(--border-width))] min-w-max">
      Closed
      <Badge size="sm">3</Badge>
    </TabsTrigger>
  </TabsList>
  <TabsContent value="open" className="text-sm text-text-secondary">12 open issues.</TabsContent>
  <TabsContent value="closed" className="text-sm text-text-secondary">3 closed issues.</TabsContent>
</Tabs>
```

### Manual activation

Arrow keys move focus; Enter or Space shows the panel.

```tsx
<Tabs defaultValue="summary" activationMode="manual" className="w-full min-w-0 max-w-full">
  <TabsList aria-label="Report" className="h-auto max-w-full flex-wrap gap-y-[max(var(--spacing-xs),calc(var(--size-target-min)-var(--size-element-md)+var(--spacing-xs)+var(--border-width)))]">
    <TabsTrigger value="summary" className="h-[calc(var(--size-element-md)-var(--spacing-xs)-var(--border-width))] min-w-max">Summary</TabsTrigger>
    <TabsTrigger value="details" className="h-[calc(var(--size-element-md)-var(--spacing-xs)-var(--border-width))] min-w-max">Details</TabsTrigger>
  </TabsList>
  <TabsContent value="summary" className="text-sm text-text-secondary">Totals for the month.</TabsContent>
  <TabsContent value="details" className="text-sm text-text-secondary">Every row of the report.</TabsContent>
</Tabs>
```

## Do and don't

### Do

- Use underline for the sections of a page or a card: Overview, Activity, Settings.
- Use segmented to switch between views of the same content in a small space, such as Grid and List.
- Keep labels to one or two words in sentence case, and few enough tabs that the row fits without scrolling.
- In one list, give every tab an icon or none of them.
- Use iconOnly only for views whose icon is clear on its own, such as Grid and List, and give each one an aria-label.
- Match the list size to the Button or Input next to it.
- Use fullWidth for two to four short tabs across a phone screen or a card, so every tab is an equal, easy target.
- When a panel loads its content, switch tabs in a transition (useTransition) and pass isPending to TabsContent as pending: the current panel stays until the next one is ready. Show a Skeleton only for a panel that has never loaded.

### Don't

- Don't use tabs to go to another page. Tabs swap panels in place; use links to navigate.
- Don't use tabs for the steps of a flow that must be done in order.
- Don't use tabs to run an action. A tab selects a panel; use Button for actions.
- Don't put tabs inside a tab panel.
- Don't use fullWidth with many tabs or long labels: equal shares cut long labels short.
- Don't restyle colors through className. Pick a variant. If none fits, open an issue instead of overriding it.
- Don't blank the panel or swap in a spinner while the next tab loads.

## Props

| Name | Type | Values | Default | Description |
| --- | --- | --- | --- | --- |
| `variant` | `enum` | `underline`, `segmented` | `underline` | Set on TabsList. underline: sections of a page or a card. segmented: switching views of the same content in a small space, such as Grid and List, or a filter next to other controls. |
| `size` | `enum` | `sm`, `md`, `lg`, `xl` | `md` | Set on TabsList. List height from size-element-*: sm 28px, md 32px (the default), lg 36px, xl 44px with a mouse; on touch md is 36px, lg 44px and xl 48px. Match the Button or Input next to it; use lg or xl for the main sections of a screen on touch. |
| `iconOnly` | `boolean` |  | `false` | Set on TabsTrigger. A square tab that shows only its icon. Needs aria-label. Not generated for iOS and Android. |
| `fullWidth` | `boolean` |  | `false` | Set on TabsList. The list fills its container and every tab takes an equal share. For a segmented control across a narrow screen, or a card whose tabs span its width. Not generated for iOS and Android. |
| `disabled` | `boolean` |  | `false` | Set on TabsTrigger. The tab can't be selected, and arrow keys skip it. |
| `defaultValue` | `string` |  |  | Set on Tabs. The value of the tab selected on first render, when you don't control it. |
| `value` | `string` |  |  | Set on Tabs. The value of the selected tab, when you control it. Pair it with onValueChange. |
| `onValueChange` | `function` |  |  | Set on Tabs. Called with the value of the newly selected tab. |
| `pending` | `boolean` |  | `false` | TabsContent: the tab the user picked is still loading. Switch tabs in a transition (useTransition) so the current panel stays on screen, and pass its isPending: the panel dims to opacity-pending and is marked aria-busy instead of going blank. Not generated for iOS and Android. |
| `pendingLabel` | `string` |  | `Loading` | TabsContent: read by screen readers in a polite status while pending. Not generated for iOS and Android. |
| `orientation` | `enum` | `horizontal`, `vertical` | `horizontal` | Set on Tabs. vertical stacks the tabs in a column at the start with the panel beside it, for a settings page with sections. Up and Down arrows move between tabs instead of Left and Right. The underline bar moves to the end edge. Not generated for iOS and Android. |
| `activationMode` | `enum` | `automatic`, `manual` | `automatic` | Set on Tabs. automatic shows a panel as soon as its tab gets focus. manual waits for Enter or Space: use it when a panel is slow to render, so arrowing past tabs does not load each one. Not generated for iOS and Android. |

Not generated: TabsContent.

### Slots

| Name | Required | Description |
| --- | --- | --- |
| `list` | yes | TabsList with one TabsTrigger per tab. Each TabsTrigger has a value. |
| `label` | no | The text of a tab: one or two words, sentence case. Overview, Activity, Settings. With iconOnly it moves to aria-label. |
| `icon` | no | Optional icon before the label, or alone with iconOnly. |
| `content` | yes | One TabsContent per tab, with the same value as its TabsTrigger. |

## Anatomy

| Part | Description |
| --- | --- |
| `root` | Tabs. Holds the selected value and stacks the list above the panels. |
| `list` | TabsList: the row of tabs. Sets variant and size for every tab in it, and takes the size-element-* height so it lines up with a Button or Input of the same size. |
| `trigger` | TabsTrigger: one tab. Stretches to the height of the list. |
| `icon` | Optional Tabler icon before the label; fill is allowed on the selected tab only. 16px in sm, md and lg, 20px in xl (DESIGN.md 9.1). |
| `indicator` | TabsList's moving selection mark: one element that slides to the selected tab when the selection changes (translate, width and height over duration-medium with ease-standard, only when the user allows motion). Underline: a 2px accent bar over the list's baseline. Segmented: the raised segment behind the selected tab. |
| `mark` | The selection mark the selected tab draws on its own ::after until the list has measured its tabs (the first paint, or before scripts run): the accent bar (underline) or the raised segment (segmented). Hidden once the indicator is placed. |
| `content` | TabsContent: the panel of one tab. Only the selected one is rendered. A newly shown panel fades in over duration-fast (at once under reduced motion). With pending it stays on screen, dims to opacity-pending (duration-medium) and is marked aria-busy, with a polite status next to it. |
| `hitArea` | Transparent ::before centered on each tab, never smaller than size-target-min (24px on mouse, 44px on touch), so small tabs stay a 44px touch target. |

## Accessibility

Role: `tablist`

| Keys | Action |
| --- | --- |
| `Tab` | Moves focus into the tab list, onto the selected tab. Tab again moves focus to the selected panel. |
| `ArrowRight, ArrowLeft` | Moves focus to the next or previous tab and selects it. Wraps from the last tab to the first and back. |
| `Home, End` | Moves focus to the first or last tab and selects it. |
| `ArrowDown, ArrowUp` | With orientation="vertical": moves focus to the next or previous tab and selects it, like ArrowRight and ArrowLeft in a horizontal list. |

- TabsList is the tablist, each TabsTrigger a button with role tab, aria-selected and aria-controls, each TabsContent a tabpanel labelled by its tab.
- The selected tab follows focus, so arrow keys show each panel right away. For panels that load slowly, pass activationMode="manual" on Tabs: arrow keys only move focus, and Enter or Space selects.
- An icon-only tab has no visible text, so it needs an aria-label. TypeScript requires one when iconOnly is set.
- A disabled tab uses the native disabled attribute: it can't be selected, and arrow keys skip it.
- Selection is never shown by color alone: underline adds the bar, segmented the raised segment, on top of the stronger text color.
- The panel is focusable, so keyboard users can reach its text even when it holds no control. It shows the focus ring.
- With orientation="vertical" the list sets aria-orientation="vertical", so screen readers announce Up and Down as the way to move.

## Install

```bash
npx werewolf-ui add tabs
```

Run `npx werewolf-ui init` once in your app before adding components. Init sets up tokens, their CSS import and agent rules. Add installs this component and its dependencies while preserving your theme. See [Installation](https://www.werewolf-ui.dev/docs/installation.md) for requirements and the alternative registry setup.

```bash
npx werewolf-ui add tabs --platform ios
npx werewolf-ui add tabs --platform android
```

For iOS and Android, run `npx werewolf-ui init --platform ios` or `npx werewolf-ui init --platform android` once, then add with `--platform`. See [Installation](https://www.werewolf-ui.dev/docs/installation.md).
