Tabs
Views of the same content that share one selection, such as a station’s summary and history. Built on Base UI Tabs. Use links instead when each view deserves its own URL.
Import
From a Server Component, import each part by name. The parts are client components that share one context, and a Server Component can’t read Tabs.List off a client component.
import { Tabs, TabsList, TabsPanel, TabsTab } from '@blocks/design-system'In a file marked 'use client', the dot API works too: Tabs.List, Tabs.Tab and Tabs.Panel are the same components.
Usage
defaultValue picks the first view and the component keeps the selection. Each TabsTab names a value that matches one TabsPanel, which takes its accessible name from that tab. A disabled tab stays visible and focusable, so readers learn it exists, but it can’t be selected.
Source · tabs/station-views.tsx
import { Tabs, TabsList, TabsPanel, TabsTab } from '@blocks/design-system'
export default function StationViews() {
return (
<Tabs defaultValue="summary">
<TabsList aria-label="Station views">
<TabsTab value="summary">Summary</TabsTab>
<TabsTab value="history">History</TabsTab>
<TabsTab value="forecast" disabled>
Forecast
</TabsTab>
</TabsList>
<TabsPanel value="summary">Current conditions</TabsPanel>
<TabsPanel value="history">Past observations</TabsPanel>
<TabsPanel value="forecast">Forecasts return in the fall.</TabsPanel>
</Tabs>
)
}Activation
By default the arrow keys move focus between tabs, and Enter or Space selects the focused one. Set activateOnFocus on TabsList when switching is cheap and the selection should follow focus.
Source · tabs/board-views.tsx
// A Server Component: the named parts cross into the client on their own.
import { Tabs, TabsList, TabsPanel, TabsTab } from '@blocks/design-system'
export default function BoardViews() {
return (
<Tabs defaultValue="list">
{/* A view activates as soon as an arrow key reaches it. */}
<TabsList aria-label="Board views" activateOnFocus>
<TabsTab value="list">List</TabsTab>
<TabsTab value="board">Board</TabsTab>
<TabsTab value="calendar">Calendar</TabsTab>
</TabsList>
<TabsPanel value="list">Twelve open items, newest first.</TabsPanel>
<TabsPanel value="board">Columns for To do, Doing and Done.</TabsPanel>
<TabsPanel value="calendar">Items placed on their due dates.</TabsPanel>
</Tabs>
)
}Controlled
Pass value and onValueChange to own the selection, for example to change it from elsewhere. State and handlers make this a client-authored example, so it uses the dot API.
Source · tabs/controlled.tsx
'use client'
import { Box, Tabs } from '@blocks/design-system'
import { useState } from 'react'
export default function Controlled() {
const [view, setView] = useState<string>('open')
return (
<Box display="flex" flexDirection="column" gap="md">
<Tabs value={view} onValueChange={(value) => setView(String(value))}>
<Tabs.List aria-label="Item filters">
<Tabs.Tab value="open">Open</Tabs.Tab>
<Tabs.Tab value="done">Done</Tabs.Tab>
</Tabs.List>
<Tabs.Panel value="open">Seven open items</Tabs.Panel>
<Tabs.Panel value="done">Five finished items</Tabs.Panel>
</Tabs>
<Box display="flex" gap="sm" alignItems="center">
<Box as="button" type="button" padding="xs" border="default" onClick={() => setView('done')}>
Show finished items
</Box>
<span>Current filter: {view}</span>
</Box>
</Box>
)
}Vertical
orientation="vertical" stacks the tabs beside the panel and switches the keys to ArrowUp and ArrowDown.
Source · tabs/vertical.tsx
import { Tabs, TabsList, TabsPanel, TabsTab } from '@blocks/design-system'
export default function Vertical() {
return (
<Tabs defaultValue="general" orientation="vertical">
<TabsList aria-label="Settings sections">
<TabsTab value="general">General</TabsTab>
<TabsTab value="members">Members</TabsTab>
<TabsTab value="billing">Billing</TabsTab>
</TabsList>
<TabsPanel value="general">Board name and description</TabsPanel>
<TabsPanel value="members">Who can edit this board</TabsPanel>
<TabsPanel value="billing">Plan and invoices</TabsPanel>
</Tabs>
)
}Keyboard
| Key | Action |
|---|---|
| Tab | Moves into the tab list at the selected tab, then into the selected panel. |
| ArrowRight / ArrowLeft | Moves to the next or previous tab, wrapping at the ends. ArrowDown / ArrowUp when vertical. |
| Home / End | Moves to the first or last tab. |
| Enter / Space | Selects the focused tab (not needed with activateOnFocus). |
Props
The parts take Base UI’s props, with dangerouslySetClassName and dangerouslySetStyle in place of className and style. render replaces the rendered element for composition.
| Prop | Type | Default | Description |
|---|---|---|---|
defaultValue | any | 0 | The default value. Use when the component is not controlled. When the value is `null`, no Tab will be active. |
onValueChange | ((value: any, eventDetails: TabsRootChangeEventDetails) => void) | — | Callback invoked when new value is being set. The event `reason` is `'none'` for user-initiated changes, such as a click or keyboard navigation; `'initial'` for the first automatic selection or fallback in uncontrolled roots when `defaultValue` is omitted or `undefined`, including when the implicit initial value is disabled or missing; `'disabled'` for automatic fallback when the selected tab becomes disabled in uncontrolled roots; or `'missing'` for automatic fallback when the selected tab is removed, or when an explicit `defaultValue` never matches a mounted tab in uncontrolled roots. For automatic changes, the selected value can be `null` when no enabled Tab is available as a fallback. Automatic changes cannot be canceled; calling `eventDetails.cancel()` for `'initial'`, `'disabled'`, or `'missing'` has no effect. |
orientation | "horizontal" | "vertical" | 'horizontal' | The component orientation (layout flow direction). |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, TabsRootState> | — | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
value | any | — | The value of the currently active `Tab`. Use when the component is controlled. When the value is `null`, no Tab will be active. |
Also accepts styling escape hatches and a ref, and the native attributes of the element it renders.
| Prop | Type | Default | Description |
|---|---|---|---|
activateOnFocus | boolean | false | Whether to automatically change the active tab on arrow key focus. Otherwise, tabs will be activated using <kbd>Enter</kbd> or <kbd>Space</kbd> key press. |
loopFocus | boolean | true | Whether to loop keyboard focus back to the first item when the end of the list is reached while using the arrow keys. |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, TabsListState> | — | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
Also accepts styling escape hatches and a ref, and the native attributes of the element it renders.
| Prop | Type | Default | Description |
|---|---|---|---|
value (required) | any | — | The value of the Tab. |
disabled | boolean | — | Whether the Tab is disabled. If a first Tab on a `<Tabs.List>` is disabled, it won't initially be selected. Instead, the next enabled Tab will be selected. However, it does not work like this during server-side rendering, as it is not known during pre-rendering which Tabs are disabled. To work around it, ensure that `defaultValue` or `value` on `<Tabs.Root>` is set to an enabled Tab's value. |
nativeButton | boolean | true | Whether the component renders a native `<button>` element when replacing it via the `render` prop. Set to `false` if the rendered element is not a button (for example, `<div>`). |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, TabsTabState> | — | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
Also accepts styling escape hatches and a ref, and the native attributes of the element it renders.
| Prop | Type | Default | Description |
|---|---|---|---|
value (required) | any | — | The value of the TabPanel. It will be shown when the Tab with the corresponding value is active. |
keepMounted | boolean | false | Whether to keep the HTML element in the DOM while the panel is hidden. |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, TabsPanelState> | — | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
Also accepts styling escape hatches and a ref, and the native attributes of the element it renders.
Accessibility
- Name every tab list with
aria-labeloraria-labelledby; the panels are named by their tabs. - Keep tab labels short and distinct, since they are announced as a set with their position.
- Content that should be reachable by URL, search or Back belongs on separate pages, not in tabs.