[ 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.

3 examplesDark modeAccessible

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.

Your project at a glance: deployments, traffic and errors.
<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#

Welcome back!
<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.

Revenue this month: ₹7,40,000

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 />

items*-
TabItem[]

Tabs to render (see below).

value-
string

Active tab (controlled).

defaultValuefirst enabled
string

Initially active tab (uncontrolled).

onChange-
(value: string) => void

Called when the active tab changes.

variant'line'
'line' | 'pills'

Visual style.

fullWidthfalse
boolean

Tabs share the full width equally.

className-
string

Class for the wrapper.

<TabItem />

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.

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).