import { Text } from "@senvenli/react/display";
import { Tabs } from "@senvenli/react/navigation";
export default function Example() {
return (
<Tabs
aria-label="Customer"
items={[
{ id: "overview", label: "Overview", panel: <Text>Ada Lovelace has been a customer since March 2024.</Text> },
{ id: "orders", label: "Orders", count: 12, panel: <Text>12 orders, the latest on March 18.</Text> },
{ id: "invoices", label: "Invoices", count: 2, panel: <Text>2 invoices are awaiting payment.</Text> },
{ id: "notes", label: "Notes", panel: <Text>Prefers delivery before noon.</Text> },
]}
/>
);
}import {
Tabs,
TabList,
Tab,
TabPanel,
SegmentedControl,
} from "@senvenli/react/navigation";Examples
Composed from parts
`TabList`, `Tab` and `TabPanel` as children: an icon in a label, panels built from your own components.import { Icon, Text } from "@senvenli/react/display";
import { Tab, TabList, TabPanel, Tabs } from "@senvenli/react/navigation";
export default function Example() {
return (
<Tabs>
<TabList aria-label="Settings">
<Tab id="profile">
<Icon name="user" size="small" />
Profile
</Tab>
<Tab id="billing" count={1}>
<Icon name="credit-card" size="small" />
Billing
</Tab>
<Tab id="team" isDisabled>
<Icon name="users" size="small" />
Team
</Tab>
</TabList>
<TabPanel id="profile">
<Text>Your name, photo and the language the app speaks to you in.</Text>
</TabPanel>
<TabPanel id="billing">
<Text>One invoice is waiting for payment.</Text>
</TabPanel>
<TabPanel id="team">
<Text>Invite people once your plan includes seats.</Text>
</TabPanel>
</Tabs>
);
}Variants and sizes
`underline` (default), `pills` and `outline`; `size` small, medium or large.import { Text } from "@senvenli/react/display";
import { Stack } from "@senvenli/react/layout";
import { Tabs } from "@senvenli/react/navigation";
const items = (name: string) => [
{ id: "overview", label: "Overview", panel: <Text>{name}: the summary of this customer.</Text> },
{ id: "orders", label: "Orders", count: 12, panel: <Text>{name}: twelve orders.</Text> },
{ id: "notes", label: "Notes", panel: <Text>{name}: prefers delivery before noon.</Text> },
];
export default function Example() {
return (
<Stack space="space-400">
<Tabs aria-label="Underline" items={items("Underline")} />
<Tabs aria-label="Pills" variant="pills" items={items("Pills")} />
<Tabs aria-label="Outline" variant="outline" size="small" items={items("Outline, small")} />
</Stack>
);
}Vertical
`orientation="vertical"`: the tabs in a column beside the panel; arrows go up and down.import { Text } from "@senvenli/react/display";
import { Tabs } from "@senvenli/react/navigation";
export default function Example() {
return (
<Tabs
aria-label="Settings"
orientation="vertical"
variant="pills"
items={[
{ id: "profile", label: "Profile", panel: <Text>Your name, photo and language.</Text> },
{ id: "billing", label: "Billing", panel: <Text>Plan, invoices and payment method.</Text> },
{ id: "team", label: "Team", panel: <Text>People and their roles.</Text> },
]}
/>
);
}Controlled
The app owns the selected tab, for example to keep it in the URL.import { Button } from "@senvenli/react/action";
import { Text } from "@senvenli/react/display";
import { Stack } from "@senvenli/react/layout";
import { Tabs } from "@senvenli/react/navigation";
import { useState } from "react";
export default function Example() {
const [tab, setTab] = useState<string | number>("open");
return (
<Stack space="space-200" align="start">
<div className="w-full">
<Tabs
aria-label="Invoices"
selectedKey={tab}
onSelectionChange={setTab}
items={[
{ id: "open", label: "Open", panel: <Text>18 invoices are open.</Text> },
{ id: "paid", label: "Paid", panel: <Text>1,186 invoices are paid.</Text> },
{ id: "overdue", label: "Overdue", panel: <Text>3 invoices are overdue.</Text> },
]}
/>
</div>
<Button variant="subtle" isDisabled={tab === "overdue"} onPress={() => setTab("overdue")}>
Show overdue invoices
</Button>
</Stack>
);
}SegmentedControl
A small set of options switched inline, with no panels of its own.import { Text } from "@senvenli/react/display";
import { Stack } from "@senvenli/react/layout";
import { SegmentedControl } from "@senvenli/react/navigation";
import { useState } from "react";
const REVENUE: Record<string, string> = { day: "$4,280", week: "$31,460", month: "$128,900" };
export default function Example() {
const [period, setPeriod] = useState<string | number>("week");
return (
<Stack direction="horizontal" space="space-200">
<SegmentedControl
label="Period"
value={period}
onChange={setPeriod}
items={[
{ id: "day", label: "Day" },
{ id: "week", label: "Week" },
{ id: "month", label: "Month" },
]}
/>
<Text isNumeric>Revenue: {REVENUE[period]}</Text>
</Stack>
);
}Guidelines
When to use it
- Two to seven views of one thing: Overview, Activity, Settings.
Use something else when
- Options act on content instead of switching views. Toggle button
Accessibility
Keyboard
| Keys | What happens |
|---|---|
| Arrow keys | Moves between tabs. |
Built in
- Tabs and panels are linked; counts are announced.
You provide
- Short nouns for tab labels.
- With children: one TabPanel per Tab, matched by the same id, and an aria-label on TabList when no heading names it.
API reference
Tabs
| Prop | Type | Default | Description |
|---|---|---|---|
items | readonly TabItem[] | – | Two to six tabs as data. Leave it out and compose |
children | React.ReactNode | – | With no |
selectedKey | Key | – | |
defaultSelectedKey | Key | – | |
onSelectionChange | (key: Key) => void | – | |
aria-label | string | – | Names the tab list when no heading above it does (with |
variant | TabsVariant | – |
|
orientation | "horizontal" | "vertical" | – |
|
size | ComponentSize | – |
|
motion | ComponentMotion | – |
|
itemsreadonly TabItem[]Two to six tabs as data. Leave it out and compose
TabList,TabandTabPanelas children instead, for a tab with an icon, a panel built elsewhere, or tabs rendered from your own components.childrenReact.ReactNodeWith no
items: aTabListofTabs followed by oneTabPanelper tab, matched byid.selectedKeyKeydefaultSelectedKeyKeyonSelectionChange(key: Key) => voidaria-labelstringNames the tab list when no heading above it does (with
items; onTabListotherwise).variantTabsVariantunderline(default): a line under the selected tab;pills: a filled tab;outline: a framed tab.orientation"horizontal" | "vertical"horizontal(default), orvertical: the tabs in a column beside the panels (settings pages).sizeComponentSizesmall,medium(default) orlarge; the provider default otherwise.motionComponentMotionauto(follow the device),reduceornone, for this component; the provider's setting otherwise.
TabList
| Prop | Type | Default | Description |
|---|---|---|---|
childrenRequired | React.ReactNode | – |
|
aria-label | string | – | Names the tab list when no heading above it does. |
aria-labelledby | string | – |
childrenRequiredReact.ReactNodeTabelements.aria-labelstringNames the tab list when no heading above it does.
aria-labelledbystring
Tab
| Prop | Type | Default | Description |
|---|---|---|---|
idRequired | Key | – | Matches the |
childrenRequired | React.ReactNode | – | The label: a noun, one or two words, optionally with an Icon before it. |
count | number | – | A count after the label (a Badge); hidden at 0. |
isDisabled | boolean | – |
idRequiredKeyMatches the
TabPanelwith the sameid.childrenRequiredReact.ReactNodeThe label: a noun, one or two words, optionally with an Icon before it.
countnumberA count after the label (a Badge); hidden at 0.
isDisabledboolean
TabPanel
| Prop | Type | Default | Description |
|---|---|---|---|
idRequired | Key | – | Matches the |
childrenRequired | React.ReactNode | – |
idRequiredKeyMatches the
Tabwith the sameid.childrenRequiredReact.ReactNode
SegmentedControl
| Prop | Type | Default | Description |
|---|---|---|---|
labelRequired | string | – | Names the group for assistive tech ("Period"); it is not shown. |
itemsRequired | readonly SegmentedControlItem[] | – | Two to five short options ("Day", "Week", "Month"). |
value | Key | – | |
defaultValue | Key | – | |
onChange | (value: Key) => void | – | |
isDisabled | boolean | – |
labelRequiredstringNames the group for assistive tech ("Period"); it is not shown.
itemsRequiredreadonly SegmentedControlItem[]Two to five short options ("Day", "Week", "Month").
valueKeydefaultValueKeyonChange(value: Key) => voidisDisabledboolean