Tabs
A tablist and the panel it controls, or a segmented mode switch.
Examples
Playground
Appearance
A second appearance (haus#60), and it is a shape rather than a weight. `underline` stays the default so nothing existing moves. `segmented` exists because a two-way mode switch is not a set of sections. core's editor toggles between Write and Preview, and a row of underlined words does not say *these are the two states of one control* the way a filled segment does. It is deliberately **not** the shared `Appearance` union, which is `subtle | solid` and means fill weight on Badge and Toast. Reusing that name would put two unrelated meanings on one type.
Size
Each size reads its label role whole: label-sm, label-md, label-lg.
Content
A disabled tab, which the arrows skip, and labels of different lengths.
Install
npx shadcn add @hipuku/tabsUsage
import { Tabs } from '@/components/haus/components/Tabs'
<Tabs
aria-label="Project"
items={[
{ label: 'Overview', value: 'overview' },
{ label: 'Activity', value: 'activity' },
]}
value={tab}
onValueChange={setTab}
>
{tab === 'overview' ? <Overview /> : <Activity />}
</Tabs>API
Tabs also takes its element's own attributes and forwards its ref. className lands on the root
and tabListClassName on the tablist.
| Prop | Type | Description |
|---|---|---|
aria-label | string | Defines a string value that labels the current element. |
itemsrequired | TabItem[] | |
valuerequired | string | |
onValueChangerequired | (value: string) => void | |
size | "sm" | "md" | "lg" | |
appearance | "underline" | "segmented" | |
tabListClassName | string | Lands on the tablist rather than the wrapper, so the label a screen reader reads for the tab group is the one the caller wrote. |
panelId | undefined |
Appearances
underline is the default, for sections. segmented fills the selected tab inside a track, for a
two or three way mode switch.
Rendering the panel yourself
Tabs renders the panel from children. When the panel has to sit elsewhere on the page, pass
panelId and an id instead, and give your panel role="tabpanel", tabIndex={0} and
aria-labelledby={tabIdFor(id, value)}, using the exported tabIdFor.
Accessibility
- A name is required, as
aria-labeloraria-labelledby. - The tablist is one tab stop. The arrow keys move between tabs and wrap, Home and End jump, and disabled tabs are skipped. Selection follows focus.
- Tab from the tablist moves into the panel.