Tabs

The Tabs component allows users to navigate between related sections of content, displaying one section at a time.

Usage

<script>
  import { 
    Tabs,
    TabsList,
    TabsTrigger,
    TabsContent
  } from "$lib/components/ui/tabs";
</script>

<Tabs defaultValue="account">
  <TabsList>
    <TabsTrigger value="account">Account</TabsTrigger>
    <TabsTrigger value="password">Password</TabsTrigger>
  </TabsList>
  <TabsContent value="account">Account settings content</TabsContent>
  <TabsContent value="password">Password settings content</TabsContent>
</Tabs>

Examples

Default

A simple tabs component with default styling.

Custom Styling

Tabs with custom styling applied to the list and content.

Disabled Tabs

Tabs with disabled triggers that cannot be selected.

API Reference

Tabs

The main container component for tabs.

PropertyTypeDefaultDescription
defaultValuestring-The value of the tab that should be active when initially rendered.
valuestring-The controlled value of the tab to activate. Should be used with onValueChange.
onValueChange(value: string) => void-Callback fired when the value changes.
orientation"horizontal" \| "vertical""horizontal"The orientation of the tabs.
classstring-Additional CSS classes to add to the tabs container.

TabsList

The container for the tab triggers.

PropertyTypeDefaultDescription
classstring-Additional CSS classes to add to the tabs list.

TabsTrigger

The button that activates its associated content.

PropertyTypeDefaultDescription
valuestringRequiredA unique value that associates the trigger with a content.
disabledbooleanfalseWhether the tab trigger is disabled.
classstring-Additional CSS classes to add to the tab trigger.

TabsContent

The content that is associated with a tab trigger.

PropertyTypeDefaultDescription
valuestringRequiredA unique value that associates the content with a trigger.
classstring-Additional CSS classes to add to the tab content.

Implementation

The Tabs component is built on top of bits-ui, a collection of headless UI components for Svelte.

// Implementation details from tabs-trigger.svelte
<TabsPrimitive.Trigger
  bind:ref
  class={cn(
    "ring-offset-background focus-visible:ring-ring data-[state=active]:bg-background data-[state=active]:text-foreground inline-flex items-center justify-center whitespace-nowrap rounded-md px-3 py-1 text-sm font-medium transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:shadow",
    className
  )}
  {value}
  {...restProps}
/>