[ Navigation ]
Tabs
Organizes content into panels where only one is visible at a time. Two styles: an underlined line (default) and segmented pills. Fully keyboard accessible.
Import#
import { Tabs } from 'reusify-ui';When to use#
- Switching between related views of the same thing: Overview / Activity / Settings.
- Segmented controls such as Day / Week / Month (pills variant).
- Don't use tabs for sequential steps. Users expect them to be independent views.
Examples#
Line (default)#
Each item has a value, a label and its content. Disabled tabs are skipped by the keyboard.
<Tabs
items={[
{ value: 'overview', label: 'Overview', content: <Overview /> },
{ value: 'activity', label: 'Activity', content: <Activity /> },
{ value: 'settings', label: 'Settings', content: <Settings /> },
{ value: 'billing', label: 'Billing', disabled: true },
]}
/>With icons#
<Tabs
items={[
{ value: 'home', label: 'Home', icon: <FiHome />, content: '…' },
{ value: 'activity', label: 'Activity', icon: <FiActivity />, content: '…' },
{ value: 'billing', label: 'Billing', icon: <FiCreditCard />, content: '…' },
]}
/>Pills, controlled#
variant="pills" renders a segmented control. Pass value + onChange to control the active tab yourself.
Current tab: month
const [tab, setTab] = useState('month');
<Tabs
variant="pills"
fullWidth
value={tab}
onChange={setTab}
items={[
{ value: 'day', label: 'Day', content: 'Revenue today: ₹24,500' },
{ value: 'week', label: 'Week', content: 'Revenue this week: ₹1,82,000' },
{ value: 'month', label: 'Month', content: 'Revenue this month: ₹7,40,000' },
]}
/>Used in designs#
Tabs in real layouts: these 2 designs use it. Open one to try it and copy the code.
API reference#
<Tabs />
| Prop | Type | Default | Description |
|---|---|---|---|
items* | TabItem[] | - | Tabs to render (see below). |
value | string | - | Active tab (controlled). |
defaultValue | string | first enabled | Initially active tab (uncontrolled). |
onChange | (value: string) => void | - | Called when the active tab changes. |
variant | 'line' | 'pills' | 'line' | Visual style. |
fullWidth | boolean | false | Tabs share the full width equally. |
className | string | - | Class for the wrapper. |
items*-TabItem[]Tabs to render (see below).
value-stringActive tab (controlled).
defaultValuefirst enabledstringInitially active tab (uncontrolled).
onChange-(value: string) => voidCalled when the active tab changes.
variant'line''line' | 'pills'Visual style.
fullWidthfalsebooleanTabs share the full width equally.
className-stringClass for the wrapper.
<TabItem />
| Prop | Type | Default | Description |
|---|---|---|---|
value* | string | - | Unique id. |
label* | ReactNode | - | Tab button text. |
content | ReactNode | - | Panel content. Omit it to use Tabs only as a switcher. |
icon | ReactNode | - | Icon before the label. |
disabled | boolean | - | Tab can't be selected. |
value*-stringUnique id.
label*-ReactNodeTab button text.
content-ReactNodePanel content. Omit it to use Tabs only as a switcher.
icon-ReactNodeIcon before the label.
disabled-booleanTab can't be selected.
Accessibility#
- Implements the WAI-ARIA tabs pattern: role="tablist", role="tab" with aria-selected/aria-controls, and role="tabpanel".
- Arrow Left/Right move between tabs (skipping disabled ones); Home and End jump to the first and last.
- Only the active tab is in the Tab order (roving tabindex).