Tabs
Panels of content shown one at a time, chosen from a row of tabs.
Installation
npx shadcn@latest add @oakoss/tabsUsage
import {
Tabs,
TabsContent,
TabsList,
TabsTrigger,
} from '#/components/ui/navigation/tabs';
<Tabs>
<TabsList aria-label="Account">
<TabsTrigger id="profile">Profile</TabsTrigger>
<TabsTrigger id="billing">Billing</TabsTrigger>
</TabsList>
<TabsContent id="profile">Your name and photo.</TabsContent>
<TabsContent id="billing">Your card and invoices.</TabsContent>
</Tabs>;Each TabsContent shares its id with a TabsTrigger.
Examples
Line
variant="line" marks the selected tab with a line under it instead of a
filled chip. The line slides to the tab selected and sizes to it, or jumps
there when the visitor prefers reduced motion. To restyle it, target its slot
from the tab, as in
className="[&_[data-slot=tabs-indicator]]:border-primary".
Vertical
orientation="vertical" stacks the tabs beside the panel. In the line look,
the line runs along the side facing the panel, on the right or, right to left,
the left.
Accessibility
React Aria renders a tablist of tabs, each linked to its tabpanel, and
the selected tab is the list's one Tab stop. Name the list with aria-label
or aria-labelledby; the type doesn't require it, since a visible heading
often names the section instead.
This component adds:
- Selected state: in Windows High Contrast the default look's selected tab takes the system's selection colors, and the line look's line is a border, which the mode keeps. The line is decorative: hidden from assistive technology, and never focused. The selected tab opts out of the text backplate the mode draws, which would hide its label. A disabled tab takes the system's disabled color, selected or not.
- Focus: tabs show the focus outline. A panel with nothing focusable inside is a Tab stop, so it shows the outline too, drawn inside its edge.
- Target size: tabs sit close together, so they don't grow to 44px; each is at least 24px tall.
| Key | Action |
|---|---|
Tab | Moves into the selected tab, then into the panel |
ArrowLeft / ArrowRight | Moves between tabs in either orientation; reversed right to left |
ArrowUp / ArrowDown | Moves between tabs when vertical |
Home / End | Moves to the first or last tab |
Space / Enter | Selects the focused tab, when keyboardActivation="manual" |
Arrow keys select the tab they move to; with keyboardActivation="manual"
they only move focus. Follows the
WAI-ARIA tabs pattern.
API
Tabs
Extends React Aria's Tabs, and
sets the look for its list and tabs.
Props
Prop
Type
Also accepts all React Aria Tabs props.
Data attributes
| Attribute | Present when |
|---|---|
data-slot | Always tabs |
data-variant | Always; default or line |
data-orientation | Always; horizontal or vertical |
data-disabled | isDisabled is set |
data-focus-visible | Something inside has keyboard focus |
TabsList
Extends React Aria's TabList, and
accepts all its props.
Data attributes
| Attribute | Present when |
|---|---|
data-slot | Always tabs-list |
data-variant | Always; the look from Tabs |
data-orientation | Always; horizontal or vertical |
TabsTrigger
Extends React Aria's Tab, and
accepts all its props. Its id is the key selectedKey refers to.
Data attributes
| Attribute | Present when |
|---|---|
data-slot | Always tabs-trigger |
data-selected | It's selected |
data-hovered | A pointer hovers it |
data-pressed | It's being pressed |
data-focus-visible | It has keyboard focus |
data-disabled | It's disabled |
In the line look, the selected tab holds the line, an element with
data-slot="tabs-indicator".
TabsContent
Extends React Aria's TabPanel, and
accepts all its props.
Data attributes
| Attribute | Present when |
|---|---|
data-slot | Always tabs-content |
data-focus-visible | It has keyboard focus |
data-inert | Its tab isn't selected, while it's kept by shouldForceMount or exiting |
data-entering | It's appearing |
data-exiting | It's leaving |