components / navigation
Tabs
Switch content with tabs and an indicator that follows the selection.
613 B gzip client componentbase ui · tabs
48 contributions this week.
tabs-default.tsx
import { Tabs, TabsList, TabsPanel, TabsTab } from "@/components/ui/tabs";
const periods = [
{ value: "day", label: "today", text: "12 contributions today." },
{ value: "week", label: "week", text: "48 contributions this week." },
{ value: "month", label: "month", text: "190 contributions this month." },
];
export default function TabsDefault() {
return (
<Tabs className="items-center" defaultValue="week">
<TabsList aria-label="Period">
{periods.map((p) => (
<TabsTab key={p.value} value={p.value}>
{p.label}
</TabsTab>
))}
</TabsList>
{periods.map((p) => (
<TabsPanel className="text-muted-foreground text-sm" key={p.value} value={p.value}>
{p.text}
</TabsPanel>
))}
</Tabs>
);
}Installation
$ npx shadcn@latest add https://cd-ui.vercel.app/r/tabs.jsonfirst time? set up components.json and the theme first: see installation.
Usage
import { Tabs, TabsList, TabsPanel, TabsTab } from "@/components/ui/tabs"
<Tabs defaultValue="a">
<TabsList>
<TabsTab value="a">A</TabsTab>
<TabsTab value="b">B</TabsTab>
</TabsList>
<TabsPanel value="a">…</TabsPanel>
</Tabs>API
Tabs
Base UI · Tabs.RootRoot.
| prop | type | default |
|---|---|---|
value · defaultValue · onValueChangeActive tab. | any | - |
classNameExtra classes, merged with | string | - |
TabsList
Base UI · Tabs.ListList with the sliding indicator (160ms, strong ease-in-out).
| prop | type | default |
|---|---|---|
classNameExtra classes, merged with | string | - |
TabsTab · TabsPanel
Base UI · Tabs.Tab · Tabs.PanelTab and content, linked by value.
| prop | type | default |
|---|---|---|
valueTab identifier. | any | - |
classNameExtra classes, merged with | string | - |
Keyboard
| key | action |
|---|---|
| ←→ | Moves between tabs. |
| HomeEnd | First and last tab. |