Skip to content
Klarhimmel UI

Tabs

The overview view.
npx shadcn add @klarhimmel/tabs

Examples

  • 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.
tabs.tsx
import { Theme } from '@/components/klarhimmel/theme/style';
import { Tabs, TabsList, TabsTrigger, TabsContent } from '@/components/klarhimmel/ui/tabs';

export default function Example() {
  return (
    <Theme theme="brand">
      <Tabs defaultValue="preview">
        <TabsList label="View">
          <TabsTrigger value="preview">Preview</TabsTrigger>
          <TabsTrigger value="code">Code</TabsTrigger>
        </TabsList>
        <TabsContent value="preview">…</TabsContent>
        <TabsContent value="code">…</TabsContent>
      </Tabs>
    </Theme>
  );
}

Import

Import

import { Tabs, TabsList, TabsTrigger, TabsContent } from '@/components/klarhimmel/ui/tabs';
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.
Tabs
├─ TabsList
│  └─ TabsTrigger (one per view)
└─ TabsContent (one per view)
  • 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

PropTypeDefaultDescription
Tabs.defaultValuestring-The open tab (Tabs).
Tabs.valuestring-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.labelstring-Accessible name of the tab list (TabsList).
TabsList.endReactNode-Underline only: an action at the right end of the line (TabsList).
TabsTrigger.valuestringrequiredThe open tab (Tabs).
TabsContent.valuestringrequiredThe open tab (Tabs).
TabsContent.childrenReactNoderequired
TabsContent.forceMounttrue-Keep a closed panel in the DOM (TabsContent).
native attributesHTMLAttributes-Every native attribute of the element passes through, className included.

Accessibility

KeyDoes
Left / RightMoves between tabs
Home / EndFirst and last tab
TabMoves into the open panel