Components
Tabs
A row of tabs that switches between panels sharing one region. The list is one tab stop with a roving focus, and choosing a tab swaps the panel.
Usage
pnpm dlx shadcn@latest add @opsinjs/tabs
The @opsinjs namespace is declared in your components.json. Everything it installs is code you then own. There is no runtime package to keep in step.
import { Tabs } from "@/components/ui/tabs"<Tabs
label="Reading detail"
value={panel}
onValueChange={setPanel}
items={[
{ value: "overview", label: "Overview", panel: <Overview /> },
{ value: "history", label: "History", panel: <History /> },
{ value: "notes", label: "Notes", panel: <Notes /> },
]}
/>Examples
tabs · base base · style base-lyraOpen under the product themeSwitching between panels
Three panels share one region, from items. Choosing a tab swaps the whole
panel, not one setting of a view.
tabs-switching-panels · base base · style base-lyraOpen under the product theme"use client"
import { useState } from "react"
import { Tabs } from "@/components/ui/tabs"
const ITEMS = [
{
value: "summary",
label: "Summary",
panel:
"A summary panel would gather the headline points here in a sentence or two. Choosing another tab hides this panel and shows a different one in the same space.",
},
{
value: "detail",
label: "Detail",
panel:
"A detail panel would carry the longer explanation, the kind a reader opens only when they want it. It is its own body of content, not a rearrangement of the summary above.",
},
{
value: "sources",
label: "Sources",
panel:
"A sources panel would list where the words came from. Nothing on any of these tabs is a measurement, a threshold or a unit, so none of it is a reading.",
},
]
export default function TabsSwitchingPanels() {
const [panel, setPanel] = useState("summary")
return (
<div className="w-full max-w-md">
<Tabs label="Example panels" value={panel} onValueChange={setPanel} items={ITEMS} />
</div>
)
}Tabs in a card
The card header names the subject and items fills its body, so a tab swaps the
body without the card moving.
tabs-in-a-card · base base · style base-lyraOpen under the product theme"use client"
import { useState } from "react"
import { Tabs } from "@/components/ui/tabs"
const ITEMS = [
{
value: "about",
label: "About",
panel:
"An about panel would describe the subject of this card in a short paragraph. It is the view a reader meets first.",
},
{
value: "activity",
label: "Activity",
panel:
"An activity panel would list what has happened recently. It replaces the about panel entirely rather than adding to it.",
},
]
export default function TabsInACard() {
const [panel, setPanel] = useState("about")
return (
<div className="w-full max-w-md rounded-opsin-lg border border-border bg-card px-opsin-4 py-opsin-3">
<p className="m-0 mb-opsin-2 text-opsin-headline font-medium [color:var(--foreground)]">
Example subject
</p>
<Tabs label="Example card views" value={panel} onValueChange={setPanel} items={ITEMS} />
</div>
)
}When to use it
Use it when
- Two or three distinct panels share one region and only one is worth showing at a time.
- Folding secondary views of one subject, such as an overview, a history and notes, behind their own tabs.
- Views a reader moves between often and expects to find in a familiar bar.
Do not use it when
- The choice sets one parameter of a view that stays on the surface, such as a chart's week window.Use
segmented-controlinstead. - The choice is a small set of exclusive options taken as a form input, submitted as a value.Use
radio-groupinstead. - The panels are steps in a sequence, where progress and a next action matter most.Use
stepperinstead.
Accessibility
Base UI's Tabs carries the tested WAI-ARIA pattern and the wrapper overrides none of
it. Activation is manual, three sighted carriers plus aria-selected mark the active
tab, and the row draws neutral chrome with no status or category axis. The indicator
glides to the chosen tab on spring-snap, and under prefers-reduced-motion it moves in
one frame. Rendered, it
shows no axe violation, target-size breach, focus gap or 320px reflow, and the audit
changed nothing.
Residual items.
- Each tab floors its height at
--opsin-target-minimumwith padding but sets nomin-w, the house treatment for a word-labelled target under SC 2.5.8. - The
labelprop applies only as the tablist'saria-label, which is right here because every tab shows its own text. - Contrast pairs for the active ink, the rail and the indicator stay unmeasured.
| Key | Action | Notes |
|---|---|---|
| Tab | Moves focus into the tab list, onto the active tab | One tab stop for the list. The active panel is the next stop. |
| Shift+Tab | Moves focus back out of the tab list | One stop in reverse too, so focus leaves the row. |
| Arrow Right, Arrow Down | Moves the highlight to the next tab | No panel swap. Wraps around, skips disabled tabs, mirrored under right-to-left. |
| Arrow Left, Arrow Up | Moves the highlight to the previous tab | Wraps to the last tab, skips disabled tabs, swaps no panel. |
| Home, End | Moves the highlight to the first or last tab | Both skip disabled tabs and neither swaps the panel. |
| Enter, Space | Activates the highlighted tab and shows its panel | The commit step of manual activation. |
Contrast: 36 measured token pairs, 15 below floor
| Pair | Theme | APCA Lc | WCAG 2.2 | Floor |
|---|---|---|---|---|
| body text on the page | light | 101.6 | 17.18:1 | Pass |
| body text on the page | dark | -100.5 | 18.00:1 | Pass |
| body text on a card | light | 104.7 | 17.96:1 | Pass |
| body text on a card | dark | -99.6 | 16.32:1 | Pass |
| body text on the muted ground | light | 98.1 | 16.32:1 | Pass |
| body text on the muted ground | dark | -97.5 | 13.77:1 | Pass |
| secondary text on the page | light | 83.9 | 7.42:1 | Pass |
| secondary text on the page | dark | -80.7 | 13.44:1 | Pass |
| secondary text on a card | light | 87.0 | 7.76:1 | Pass |
| secondary text on a card | dark | -79.8 | 12.19:1 | Pass |
| secondary text on the muted ground | light | 80.4 | 7.05:1 | Pass |
| secondary text on the muted ground | dark | -77.8 | 10.28:1 | Pass |
| a hairline boundary on the page | light | 19.3 | 1.41:1 | Below floor |
| a hairline boundary on the page | dark | -8.2 | 1.90:1 | Below floor |
| a hairline boundary on a card | light | 22.4 | 1.47:1 | Below floor |
| a hairline boundary on a card | dark | -7.3 | 1.72:1 | Below floor |
| a hairline boundary on the muted ground | light | 15.8 | 1.34:1 | Below floor |
| a hairline boundary on the muted ground | dark | 0.0 | 1.45:1 | Below floor |
| a placeholder boundary on the page | light | 69.8 | 4.52:1 | Pass |
| a placeholder boundary on the page | dark | -51.0 | 7.62:1 | Pass |
| a placeholder boundary on a card | light | 72.8 | 4.72:1 | Pass |
| a placeholder boundary on a card | dark | -50.1 | 6.91:1 | Pass |
| a placeholder boundary on the muted ground | light | 66.2 | 4.29:1 | Pass |
| a placeholder boundary on the muted ground | dark | -48.1 | 5.83:1 | Pass |
| a placeholder fill on the page | light | 8.3 | 1.18:1 | Below floor |
| a placeholder fill on the page | dark | -8.2 | 1.90:1 | Below floor |
| a placeholder fill on a card | light | 11.4 | 1.23:1 | Below floor |
| a placeholder fill on a card | dark | -7.3 | 1.72:1 | Below floor |
| a placeholder fill on the muted ground | light | 0.0 | 1.12:1 | Below floor |
| a placeholder fill on the muted ground | dark | 0.0 | 1.45:1 | Below floor |
| a placeholder boundary on its own fill | light | 58.9 | 3.84:1 | Pass |
| a placeholder boundary on its own fill | dark | -41.5 | 4.01:1 | Below floor |
| the card hairline on the page | light | 69.8 | 4.52:1 | Pass |
| the card hairline on the page | dark | -28.7 | 4.19:1 | Below floor |
| the card hairline on a card | light | 72.8 | 4.72:1 | Pass |
| the card hairline on a card | dark | -27.9 | 3.80:1 | Below floor |
These are the measured token pairs this component draws colour from, not a measurement of the component itself.
Props interface
Prop
Type
Generated from TabsProps in registry/bases/base/tabs.tsx.
value and onValueChange make this controlled, with no internal selection
state. A value matching no item renders no active tab and warns in
development. items holds each tab's value, label and panel together.