nook
Browse the docs

Components

Tabs

Built on Base UI

Switch between related panels with an animated active indicator.

See the prompt
Make changes to your account here.

Installation

npx nook-ui@latest add tabs

Prompt

Paste this into your AI coding assistant. It adds this exact component, the same way the CLI does, and tells the assistant how to use it.

Short. For assistants that can run commands in your project.

Plain text
Add the Nook "Tabs" component to this project, exactly as Nook ships it.

Switch between related panels with an animated active indicator.

Steps
1. Check for `nook.json` in the project root. If it is missing, run `npx nook-ui@latest init` first (React or Next.js with Tailwind CSS v4). It adds the Nook tokens, the theme and `cn()`.
2. Run `npx nook-ui@latest add tabs`. It writes `components/ui/tabs.tsx` together with everything the component needs. Do not write the component from memory.
3. If you cannot run commands, fetch http://localhost:3000/r/tabs.json, write every entry of `files` to the path it names, install the packages in `dependencies`, and repeat for each name in `registryDependencies`.
4. Use it where I ask. Start from this example:

```tsx
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";

export default function TabsDefault() {
  return (
    <Tabs defaultValue="account" className="w-full max-w-md">
      <TabsList aria-label="Settings">
        <TabsTrigger value="account">Account</TabsTrigger>
        <TabsTrigger value="password">Password</TabsTrigger>
        <TabsTrigger value="billing">Billing</TabsTrigger>
      </TabsList>
      <TabsContent value="account" className="p-1 text-sm">
        Make changes to your account here.
      </TabsContent>
      <TabsContent value="password" className="p-1 text-sm">
        Change your password here.
      </TabsContent>
      <TabsContent value="billing" className="p-1 text-sm">
        See invoices and update your card.
      </TabsContent>
    </Tabs>
  );
}
```

API
- `Tabs`: Owns the active tab.
  - `value` (`string`): Controlled active tab.
  - `defaultValue` (`string`): Initial tab when uncontrolled.
  - `onValueChange` (`(value: string) => void`): Called when the active tab changes.
  - `orientation` (`"horizontal" | "vertical"`, default "horizontal"): Direction of the tab list.
- `TabsList`: Holds the triggers and the indicator.
- `TabsTrigger`: One tab button.
  - `value` (`string`): Links the trigger to a panel.
  - `disabled` (`boolean`, default false): Disables the tab.
- `TabsContent`: The panel for a tab.
  - `value` (`string`): Matches a trigger value.
- Variant `orientation`: horizontal, vertical (default horizontal)

Rules
- Colors, radii, shadows and motion come from Nook tokens and classes such as `bg-primary`, `text-muted-foreground`, `border-border`, `rounded-lg` and `h-control`. Never hard-code them.
- Do not restyle or simplify the file. Change how it looks through `className`, its props and the theme.
- It must keep working with the keyboard, in light and dark mode, and in the sharp, soft and bold styles.
- Accessibility: Arrow keys move between tabs, Home and End jump to the ends. Name the list with `aria-label`.

Done when the component renders like the example in light and dark mode and the project type-checks.

Usage

import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";

export default function TabsDefault() {
  return (
    <Tabs defaultValue="account" className="w-full max-w-md">
      <TabsList aria-label="Settings">
        <TabsTrigger value="account">Account</TabsTrigger>
        <TabsTrigger value="password">Password</TabsTrigger>
        <TabsTrigger value="billing">Billing</TabsTrigger>
      </TabsList>
      <TabsContent value="account" className="p-1 text-sm">
        Make changes to your account here.
      </TabsContent>
      <TabsContent value="password" className="p-1 text-sm">
        Change your password here.
      </TabsContent>
      <TabsContent value="billing" className="p-1 text-sm">
        See invoices and update your card.
      </TabsContent>
    </Tabs>
  );
}

Examples

Vertical

Your name and photo appear on comments and invoices.

With counts

24 issues need attention. The oldest was opened 6 days ago.

Disabled tab

Billing opens once you upgrade to a paid plan.

Many tabs

Monday: 8:00 to 18:00.

Variants

Defined in one place with cva, at the top of the component file.

  • orientation

    horizontal (default)vertical

Props

Tabs

Owns the active tab.

PropTypeDefaultDescription
valuestring–Controlled active tab.
defaultValuestring–Initial tab when uncontrolled.
onValueChange(value: string) => void–Called when the active tab changes.
orientation"horizontal" | "vertical""horizontal"Direction of the tab list.

TabsList

Holds the triggers and the indicator.

TabsTrigger

One tab button.

PropTypeDefaultDescription
valuestring–Links the trigger to a panel.
disabledbooleanfalseDisables the tab.

TabsContent

The panel for a tab.

PropTypeDefaultDescription
valuestring–Matches a trigger value.

Accessibility

Arrow keys move between tabs, Home and End jump to the ends. Name the list with `aria-label`.

Checked against WCAG 2.1 AA with automated axe tests and keyboard tests on every release.