Tabs
Switches between sections or views: one shows at a time.
<Tabs defaultValue="overview"> <TabsList aria-label="Agent"> <TabsTrigger value="overview">Overview</TabsTrigger> <TabsTrigger value="runs" count={4}>Runs</TabsTrigger> <TabsTrigger value="security">Security</TabsTrigger> <TabsTrigger value="settings">Settings</TabsTrigger> </TabsList></Tabs>Installation
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@catalog-developer/components";Usage
A TabsContent per tab, with the tab's value. Only the selected panel is in the page; keepMounted keeps the others, with their state. A list can also stand without panels and drive a value you hold.
<Tabs defaultValue="overview"> <TabsList aria-label="Agent"> <TabsTrigger value="overview">Overview</TabsTrigger> <TabsTrigger value="runs">Runs</TabsTrigger> </TabsList> <TabsContent value="overview">What the agent is.</TabsContent> <TabsContent value="runs">What it did.</TabsContent></Tabs>Anatomy
- 1 — List. The row. A segment's list is a track; a simple list has none.
- 2 — Selected fill. One fill, drawn by the list, that moves to the tab you pick. In a track it sits 2px inside, its corners 2 less than the track's.
- 3 — Count. Plain text a size under the label.
- 4 — Icon. Before the label, in the label's color.
- 5 — Label. Full color when selected, secondary otherwise.
Variants
simple, the default: the selected tab takes a quiet fill, with no track. segment: a picker in a track, built as the secondary Button. line is the older underlined row, being phased out.
<TabsList variant="simple">…</TabsList><TabsList variant="segment">…</TabsList>Sizes
Four, matching the control scale: md, sm, xs, and xxs. A segment's track is 32, 28, 24, and 20px tall; a simple tab follows the same scale.
<TabsList variant="segment" size="md">…</TabsList><TabsList variant="segment" size="sm">…</TabsList><TabsList variant="segment" size="xs">…</TabsList><TabsList variant="segment" size="xxs">…</TabsList>Width
hug, the default: each tab as wide as its content. fill: the list takes its container and the tabs share it equally.
<TabsList variant="segment" width="fill">…</TabsList>Icons
iconStart puts an icon before the label. With iconOnly the icon shows alone: the label becomes the tab's tooltip (above, or to the right in vertical tabs) and stays its name for a screen reader.
<TabsTrigger value="overview" iconStart={House}>Overview</TabsTrigger><TabsTrigger value="grants" iconStart={Key}>Grants</TabsTrigger><TabsTrigger value="security" iconStart={Shield}>Security</TabsTrigger> <TabsTrigger value="list" iconStart={ListBullets} iconOnly>List</TabsTrigger><TabsTrigger value="grid" iconStart={Grid} iconOnly>Grid</TabsTrigger>Counts
count ends a tab in plain text, a size under the label: muted, or with countColor a status's text color. A number is grouped for the reader (1,204). New, not used by a screen yet: a string is shown as it is ("99+"). The dashboard's own wrapper (components/ui/tabs.tsx) still takes a number only.
<TabsTrigger value="all" count={1204}>All</TabsTrigger><TabsTrigger value="failed" count={3} countColor="error">Failed</TabsTrigger><TabsTrigger value="queued" count="99+">Queued</TabsTrigger>A badge
badge ends a tab in a Badge, in the Badge's own shape (label, color, emphasis, icons, title). The tab sizes it: the 20px badge in a tab 28px tall or more, the 16px one under that. The badge sits as far from the tab's end as from its top and bottom: 6px in a 32px tab, 4px in a 28px or 24px one, 2px in a 20px one. The smallest segment tab is as tall as its badge, which keeps 2px from the tab's end. A tab without a badge keeps its own padding. No screen has a tab with a badge today. Below, each size as simple tabs and as a segment.
<TabsTrigger value="all">All</TabsTrigger><TabsTrigger value="managed" badge={{ label: "Preview", color: "info" }}>Managed</TabsTrigger><TabsTrigger value="external">External</TabsTrigger>An info icon
iconTooltip puts a small info icon after the label, with a few words on hover. Only a pointer reaches it; see the open question.
<TabsTrigger value="written">Written</TabsTrigger><TabsTrigger value="effective" iconTooltip="What applies after every scope is merged.">Effective</TabsTrigger>A tab to something dangerous
variant="destructive" is a tab that leads to something dangerous (a Danger zone): red text at rest, on hover and selected, over a tint of that red under the pointer (the red ghost Button's). A simple tab's selected fill is tinted red too, a step stronger; a selected segment tab changes its text only.
<TabsTrigger value="general">General</TabsTrigger><TabsTrigger value="members">Members</TabsTrigger><TabsTrigger value="danger" variant="destructive">Danger zone</TabsTrigger>Vertical
The same tabs in a column.
<Tabs orientation="vertical" defaultValue="general"> <TabsList aria-label="Settings"> <TabsTrigger value="general">General</TabsTrigger> <TabsTrigger value="members">Members</TabsTrigger> <TabsTrigger value="billing">Billing</TabsTrigger> </TabsList></Tabs>Motion
The selected fill is drawn once by the list and moves between tabs. auto, the default, slides it to a near tab and fades it to a far one (past slideDistance, 240px). slide and fade force one; none cuts, and so does reduced motion.
<TabsList motion="auto">…</TabsList><TabsList motion="none">…</TabsList>In the dashboard
Where tabs are drawn today. The first two are not this component underneath: they are links and buttons in its classes. Sections and the Docs switch change the address; the two splits change a value in place.
Audit's sections
Overview, Activity chains, Event log, Resource directory. Each is a link with its own address: SegmentedTabNav draws links in the Tabs' simple look.
components/layout/segmented-tab-nav.tsx
An agent's sections
Overview, Runs, Topology, Guards, Security, Settings. DetailPageView draws its own tab list in the Tabs' classes; each tab is a link, or a button that sets the address's hash.
components/layout/detail-page-view.tsx
A list's split
All, Managed, External over the agents: a segment today. The ds Table draws the same split as simple tabs at its bar's left.
components/agents/agent-table.tsx
A feed's result
All, Allowed, Denied, Errors over an agent's activity: a segment, Allowed's count in green, Denied's and Errors' in red.
components/agents/activity-feed.tsx
Docs or Playground
The switch at the top of this page: a small segment whose two tabs are two addresses.
catalog/app/_components/catalog-mode.tsx
Accessibility
Base UI gives the roles: a tab list, its tabs, and a panel tied to each tab, the selected one marked. The list has no name unless you give it one with aria-label; the activity feed's has none today.
The Tab key enters the row on the selected tab. Inside the row the arrow keys move between tabs, Home and End jump to the first and last, and the row wraps at its ends. An arrow moves the focus and does not select: Enter or Space selects. activateOnFocus on the list makes arrows select as they move.
An icon-only tab keeps its label as its name. A count is inside the tab, so it is part of the name: "Failed 3". A badge is decoration and is not: a tab named "Managed" stays "Managed".
What does not hold up today: the info icon of iconTooltip is reached by a pointer only. The open panel takes focus and draws no ring. And the small tabs are under the 24px that WCAG 2.2 asks of a pointer target: an xs segment tab and an xxs simple tab are 20px tall, an xxs segment tab 16px.
API Reference
Tabs
| Prop | Type | Default | Description |
|---|---|---|---|
defaultValue | string | — | The tab selected at first. Without it the first enabled tab is selected. |
value / onValueChange | string / (value) => void | — | The selection, held by you. |
orientation | "horizontal" | "vertical" | "horizontal" | A row, or a column. |
TabsList
| Prop | Type | Default | Description |
|---|---|---|---|
variant | "simple" | "segment" | "line" | "simple" | No track, a track, or the older underlined row. |
size | "lg" | "md" | "sm" | "xs" | "xxs" | "md" | In a card's header, toolbar or footer it is 28px at most. |
width | "hug" | "fill" | "hug" | Each tab its content's width, or the tabs sharing the container. |
motion | "auto" | "slide" | "fade" | "none" | "auto" | How the selected fill moves to the next tab. |
slideDistance | number | 240 | Under auto, how far the fill slides before it fades instead, in px. |
activateOnFocus | boolean | false | Arrows select as they move, instead of waiting for Enter or Space. |
aria-label | string | — | The list's name for a screen reader. |
TabsTrigger
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | — | Which panel it shows. |
iconStart | IconComponent | — | An icon before the label. |
dot | { color?, size?, halo?, haloSize?, pulse? } | — | A Status dot before the label, in the icon's place and its box (14px, 10px in an xxs tab). With a dot, iconStart is not drawn and iconOnly does nothing. |
iconOnly | boolean | tooltip settings | — | With iconStart: the icon alone, the label as its tooltip and its name. |
iconTooltip | string | tooltip settings | — | An info icon after the label, with text on hover. Not on an icon-only tab. |
count | number | string | — | A count after the label. A number is grouped for the reader. The string form is new and no screen uses it yet. |
countColor | BadgeColor | "neutral" | A status's text color for the count. |
badge | BadgeSpec | — | A Badge at the tab's end: { label, color?, emphasis?, iconStart?, iconEnd?, title? }. Not in the tab's name. |
variant | "default" | "destructive" | "default" | destructive: a tab that leads to something dangerous (a Danger zone), in red. |
disabled | boolean | — | The tab cannot be selected. |
TabsContent
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | — | The tab it belongs to. |
keepMounted | boolean | false | Keep the panel in the page while another is shown, with its state. |
Rules
Written down
28px at most in a card's header, toolbar or footer
A list asked for at medium renders small there. The list does it itself; nothing is set per screen.
From ds/README.md (Card) and ds/lib/size-cap.tsx.
A table's one split is its tabs
A split like All / Managed / External is the tabs at the left of the table's bar, after the title: it filters, with no chip. Everything else that narrows the list is the Filter. Short of room, those tabs become one select.
From the Table's rules (T10, T13).
Red is a tab that leads to something dangerous
variant="destructive" is for a Danger zone tab.
From ds/components/tabs.tsx.
line is being phased out
The underlined row stays for what already uses it. The dashboard's own Tabs map it to simple under the new design.
From ds/components/tabs.tsx and ds/README.md.
Open questions
Tabs, or a toggle group, for a value changed in place?
OpenThe README says: Tabs move you somewhere (a section, a URL, the panel below), a toggle group changes a value in place (a filter, a view, a unit), and "Dome uses Tabs for both today". The ds has a ToggleGroup. For a table's split the answer is written (tabs); outside a table, nothing written chooses.
Primer's segmented control is not announced as a tab list. Atlassian says not to use tabs for filtering data within a single table. Polaris shows tabs over a list view with different filters applied.
A row of links, or Tabs, when the address changes?
OpenThe product does three things: Audit's sections are links (SegmentedTabNav), an agent's sections are a hand-built tab list of links and hash buttons (DetailPageView), and the Docs switch is Tabs that navigate. Nothing written chooses.
Primer keeps tabs that change the URL in a separate navigation component, made of links. Base UI and Polaris let a tab be a link.
Should an arrow key select the tab it lands on?
OpenIt does not: an arrow moves the focus and Enter or Space selects, which is Base UI's default. No screen turns the other way on.
Atlassian selects on focus. Primer selects on focus by default, and offers the manual way for panels that do not show at once.
What happens when the tabs do not fit?
OpenNothing: the row keeps its width and no tab wraps or hides. The one exception is a table's bar, where the tabs become one select.
Primer moves the tabs that do not fit into a menu, and can drop their icons when narrow. Polaris measures the tabs and puts the rest in a popover.
An info icon in a tab?
OpeniconTooltip exists and only a pointer reaches it.
They disagree. Primer: don't rely on icons or tooltips to explain a tab. Atlassian: a tooltip can say what happens when the tab is selected.
What others advise
None of this is decided for us. It is what Atlassian, Polaris and Primer tell their own teams, listed so you can pick.
| Others advise | Who |
|---|---|
| Don't use tabs as primary navigation, or to move between different pages. | Polaris, Atlassian |
| Each tab's content stands alone: nobody should have to switch tabs to finish one task. | Polaris, Primer |
| What relates to every tab goes above the row. | Atlassian |
| One tab is selected when the row first shows. | Primer |
| Order tabs by importance or by how often they are used. | Atlassian |
| Labels of one or two words (Atlassian), a single word where possible (Polaris). | Atlassian, Polaris |
| Icons on every tab of a row, or on none. | Primer |
| A segmented control holds two to five text options, or up to six icons; past that, a radio group or a menu. | Primer |
| Tabs sit directly above their content, and are no wider than it. | Primer |
What others expose
What Base UI, Atlassian, Polaris and Primer offer for tabs, and where ours stands on each.
| They expose | Ours | Why |
|---|---|---|
| A count given as text (Primer, Polaris) | Added | New, not used by a screen yet: count takes a string. |
| Arrows that select as they move (Base UI, Primer, Atlassian) | Already there | activateOnFocus on the list. |
| A marker that follows the selected tab (Base UI) | Already there | The list's fill and its motion. |
| Tabs that share the width (Polaris) | Already there | width="fill". |
| Hidden panels kept in the page (Base UI) | Already there | keepMounted on TabsContent. |
| A tab that is a link (Base UI, Polaris) | Ask | Not on the ds Tabs. SegmentedTabNav and DetailPageView each draw their own. |
| A menu for the tabs that do not fit, and icons dropped when narrow (Primer, Polaris) | Ask | Only the Table's bar gives way today. |
| A placeholder for counts that are still loading (Primer) | Ask | Primer itself says to avoid it until its accessibility issues are resolved. |
| Actions on a tab: rename, duplicate, delete (Polaris) | Ask | The dashboard has no saved views today. |