Tabs
Web/MobileA set of layered sections of content, known as tab panels, displayed one at a time.
Installation
pnpm dlx cubix-ui@latest add tabs --base radixUsage
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/cubix/tabs"
<Tabs defaultValue="account" className="w-full max-w-md">
<TabsList aria-label="تنظیمات حساب">
<TabsTrigger value="account">حساب کاربری</TabsTrigger>
<TabsTrigger value="password">رمز عبور</TabsTrigger>
</TabsList>
<TabsContent value="account" className="rounded-lg border p-4 text-muted-foreground">
نام، ایمیل و تصویر نمایه خود را از این بخش تغییر دهید.
</TabsContent>
<TabsContent value="password" className="rounded-lg border p-4 text-muted-foreground">
برای امنیت بیشتر، رمز عبور خود را هر چند ماه یک بار عوض کنید.
</TabsContent>
</Tabs>
Composition
Every TabsTrigger is paired with a TabsContent that has the same value. Tabs start right-to-left and follow the closest dir on the page; pass dir to override it.
Tabs
├── TabsList
│ └── TabsTrigger (value)
└── TabsContent (value)Accessibility
The list renders role="tablist", each trigger role="tab" with aria-selected, and each panel role="tabpanel" linked to its tab. Name the list with aria-label. The list is a single tab stop and arrow keys follow the reading direction. Removable tabs announce their Delete and Backspace shortcuts through aria-keyshortcuts.
| Key | Action |
|---|---|
| Tab | Moves focus into the list onto the active tab, then out to the active panel. |
| ArrowLeft / ArrowRight | Moves to the next or previous tab in reading direction, so the keys are mirrored in RTL. Selection follows focus. |
| ArrowUp / ArrowDown | Moves to the previous or next tab when orientation is vertical. |
| Home / End | Moves to the first or last enabled tab. |
| Delete / Backspace | Removes the focused tab when it has onRemove. Focus moves to the neighboring tab. |
Examples
With icons
Put an icon inside the trigger and mark it with data-icon="inline-start" so spacing follows the reading direction.
Removable
Pass onRemove to a trigger to add a remove control at its end. When the active tab is removed, select its neighbor in the same handler.
Vertical
Use orientation="vertical" to stack the triggers. The list is placed at the inline start and ArrowUp / ArrowDown move between tabs.
Disabled tab
A disabled trigger cannot be selected, and arrow key navigation skips it.
Controlled
Pass value and onValueChange to own the active tab, for example to drive it from step buttons.
Custom styling
Every base marks the active trigger with aria-selected="true", so one set of aria-selected: classes styles it on Base UI, React Aria, and Radix.
API Reference
Note: Parts render data-slot attributes (tabs, tabs-list, tabs-trigger, tabs-remove, tabs-content) for targeting in tests and parent selectors. Use the same props on Base UI, React Aria, and Radix.
Tabs
| Prop | Type | Default | Description |
|---|---|---|---|
| value | string | - | Controlled active tab value. Use with `onValueChange`. |
| defaultValue | string | - | Default active tab value for uncontrolled usage. |
| onValueChange | (value: string) => void | - | Called when a tab trigger selects a new value. |
| dir | "ltr" | "rtl" | closest dir on the page (rtl if none) | The reading direction. It sets the arrow-key direction and where the list sits. |
| orientation | "horizontal" | "vertical" | "horizontal" | The orientation of the tabs list and triggers. |
| className | string | - | Additional Tailwind classes merged with the root styles. |
TabsList
| Prop | Type | Default | Description |
|---|---|---|---|
| variant | "line" | "line" | The visual style of the tabs list. Tabs are always the underline style; use Segmented Control for a filled pill switcher. |
| aria-label | string | - | Names the group of tabs for screen readers. |
| className | string | - | Additional Tailwind classes merged with the list styles. |
TabsTrigger
| Prop | Type | Default | Description |
|---|---|---|---|
| value | string | - | The tab value selected by this trigger. |
| disabled | boolean | false | Disables the trigger and prevents interaction. |
| onRemove | () => void | - | Adds a remove control at the end of the trigger. Called when it is clicked, or when Delete or Backspace is pressed on the focused tab. Focus moves to the neighboring tab. |
| className | string | - | Additional Tailwind classes merged with the trigger styles. |
TabsContent
| Prop | Type | Default | Description |
|---|---|---|---|
| value | string | - | The tab value that controls when this panel is shown. |
| className | string | - | Additional Tailwind classes merged with the content styles. |