Tabs
Switch between views in the same place. Follows the ARIA tabs pattern: one tab stop, arrows (and Home/End) move and activate, panels are linked to their tabs.
import { Tab, TabList, TabPanel, Tabs } from "pixelbits/tabs";
export default function Demo() {
return (
<div className="grid w-full max-w-md gap-8">
<Tabs defaultValue="preview">
<TabList aria-label="Example">
<Tab value="preview">Preview</Tab>
<Tab value="code">Code</Tab>
<Tab value="props">Props</Tab>
</TabList>
<TabPanel value="preview" className="text-sm text-pb-muted">
The preview.
</TabPanel>
<TabPanel value="code" className="font-pb-mono text-xs">
{"<Button />"}
</TabPanel>
<TabPanel value="props" className="text-sm">
The props table.
</TabPanel>
</Tabs>
<Tabs defaultValue="dark" variant="segmented">
<TabList aria-label="Theme">
<Tab value="dark">Dark</Tab>
<Tab value="light">Light</Tab>
<Tab value="system">System</Tab>
</TabList>
</Tabs>
</div>
);
}Installation
import { Tabs, TabList, Tab, TabPanel } from "pixelbits/tabs";npx shadcn add https://pixelbits.ali-moradi-develop.com/r/tabs.jsonAPI
<Tabs>
Switch between views in the same place. Follows the ARIA tabs pattern: one tab stop, arrows (and Home/End) move and activate, panels are linked to their tabs.
<Tabs defaultValue="preview">
<TabList aria-label="Example">
<Tab value="preview">Preview</Tab>
<Tab value="code">Code</Tab>
</TabList>
<TabPanel value="preview">…</TabPanel>
<TabPanel value="code">…</TabPanel>
</Tabs>| Prop | Type | Default | Description |
|---|---|---|---|
| value | string | — | The active tab's value (controlled). |
| defaultValue | string | — | The tab active at first (uncontrolled). |
| onValueChange | (value: string) => void | — | Called with the value of the tab the user activated. |
| variant | "underline" | "segmented" | "underline" | Look of the tab list.
|
| keepMounted | boolean | false | Keep inactive panels in the DOM (hidden) to preserve their state. By default only the active panel is rendered. |
| withPanels | boolean | true | Set |
| children* | ReactNode | — |
|
Also accepts every prop of Omit<HTMLAttributes<HTMLDivElement>, "defaultValue">.
<TabList>
The row of tabs. Handles arrow-key navigation between them.
| Prop | Type | Default | Description |
|---|---|---|---|
| children* | ReactNode | — | The |
Also accepts every prop of HTMLAttributes<HTMLDivElement>.
<Tab>
One tab. Activating it shows the TabPanel with the same value.
| Prop | Type | Default | Description |
|---|---|---|---|
| value* | string | — | Identifies the tab and its |
Also accepts every prop of ButtonHTMLAttributes<HTMLButtonElement>.
<TabPanel>
The content shown while its Tab is active.
| Prop | Type | Default | Description |
|---|---|---|---|
| value* | string | — | The |
Also accepts every prop of HTMLAttributes<HTMLDivElement>.