Tabs

Slant / Navigation

Tabs with a sliding indicator and arrow-key navigation.

Demo

Tabs

Usage

@tuttn/slant
import { Badge, Tabs } from '@tuttn/slant'

// Uniform tabs: an items array.
const items = [
  { id: 'overview', label: 'Overview', content: <Overview /> },
  { id: 'activity', label: 'Activity', content: <Activity /> },
  { id: 'files', label: 'Files', content: <Files />, disabled: true },
] as const

// Uncontrolled: starts at defaultValue (the first enabled tab when omitted).
<Tabs items={items} defaultValue="overview" label="Task details" />
// Controlled: you hold the value.
<Tabs items={items} value={tab} onValueChange={setTab} label="Task details" />

// Rich tabs: the compound parts, here as a column beside the panels.
<Tabs defaultValue="activity" orientation="vertical">
  <Tabs.List label="Task details">
    <Tabs.Tab value="overview">Overview</Tabs.Tab>
    <Tabs.Tab value="activity">Activity <Badge mono>3</Badge></Tabs.Tab>
  </Tabs.List>
  <Tabs.Panel value="overview"><Overview /></Tabs.Panel>
  <Tabs.Panel value="activity"><Activity /></Tabs.Panel>
</Tabs>

Props

PropTypeDefaultDescription
itemsreadonly TabItem<T>[]—The tabs and their panels, for uniform content. Leave it out and compose `Tabs.List`, `Tabs.Tab` and `Tabs.Panel` as children instead.
valueT—The selected tab, when controlled. A value that names no tab shows the first enabled one.
defaultValueTthe first enabled tabThe tab selected first, when uncontrolled.
onValueChange(value: T) => void—Called with the tab's value when the user selects another tab.
labelstring—The tablist's accessible name. With `items` it names the list Tabs renders; in the compound form `Tabs.List`'s own `label` wins.
orientation'horizontal' | 'vertical''horizontal'A row of tabs over the panels (left and right arrows, swapped under RTL), or a column beside them (up and down arrows).
Tabs.List labelstring—The tablist's accessible name; falls back to the root's label.
Tabs.Tab valuestring—Which tab this is; the Tabs.Panel with the same value is its panel.
Tabs.Tab disabledboolean—Takes the tab out of clicks and arrow keys.
Tabs.Panel valuestring—The Tabs.Tab this panel belongs to.
…restHTMLAttributes—className, style, other attributes and the ref go on each part's own element: the root div, the tablist div, the tab button and the panel div.

An item is { id, label, content, disabled? }; the ids type value and onValueChange. Activation is automatic: the arrows select as they move, and skip disabled tabs. In a row, left and right swap under right-to-left text; in a column, up and down move.

Every panel stays mounted, so its state survives a tab switch, and the unselected ones are hidden. The indicator follows the selected tab whenever the list or a tab changes size.

Full source