Tabs
The overview view.
npx shadcn add @klarhimmel/tabsCopy for AIExamples
Basic
Starting tab and a disabled tab
DetailsAbout, usage, props and more
Switch between views of the same thing. Built on Radix Tabs, arrow keys move between tabs.
When to use
Use for
Two to five views of the same subject, like Preview and Code.
Not for
Navigation between pages. Use links.
Pairs with
Preview frames, settings panels.
Preview
A summary of the project.
Import
Import
- Files
- tabs.tsx, in components/klarhimmel/ui/. With it: theme, utils.
- Render in
- Render it inside <Theme>, once near the root of your app. Tokens and fonts are scoped to it, so outside it the component is unstyled.
Anatomy
The parts and how they nest.
A summary of the project.
TabsHolds the open value. Controlled or uncontrolled.TabsListThe row of triggers. Takes the accessible name.TabsTriggerOne per view, paired to its content by value.TabsContentThe panel shown for its value.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
Tabs.defaultValue | string | - | The open tab (Tabs). |
Tabs.value | string | - | The open tab (Tabs). |
Tabs.onValueChange | (v: string) => void | - | |
Tabs.variant | 'pill' | 'underline' | 'pill' | Pill: a segmented control. Underline: a page's sections on one hairline (Tabs). |
TabsList.label | string | - | Accessible name of the tab list (TabsList). |
TabsList.end | ReactNode | - | Underline only: an action at the right end of the line (TabsList). |
TabsTrigger.value | string | required | The open tab (Tabs). |
TabsContent.value | string | required | The open tab (Tabs). |
TabsContent.children | ReactNode | required | |
TabsContent.forceMount | true | - | Keep a closed panel in the DOM (TabsContent). |
native attributes | HTMLAttributes | - | Every native attribute of the element passes through, className included. |
Accessibility
| Key | Does |
|---|---|
Left / Right | Moves between tabs |
Home / End | First and last tab |
Tab | Moves into the open panel |