Tabs
A set of layered sections of content—known as tab panels—that are displayed one at a time.
Overview
View your key metrics and recent project activity. Track progress across all your active projects.
You have 12 active projects and 3 pending tasks.
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle
} from "~/components/ui/card"
import { Tabs, TabsContent, TabsList, TabsTrigger } from "~/components/ui/tabs"
export default function TabsDemo() {
return (
<Tabs defaultValue="overview" class="w-[400px]">
<TabsList>
<TabsTrigger value="overview">Overview</TabsTrigger>
<TabsTrigger value="analytics">Analytics</TabsTrigger>
<TabsTrigger value="reports">Reports</TabsTrigger>
<TabsTrigger value="settings">Settings</TabsTrigger>
</TabsList>
<TabsContent value="overview">
<Card>
<CardHeader>
<CardTitle>Overview</CardTitle>
<CardDescription>
View your key metrics and recent project activity. Track progress
across all your active projects.
</CardDescription>
</CardHeader>
<CardContent class="text-sm text-muted-foreground">
You have 12 active projects and 3 pending tasks.
</CardContent>
</Card>
</TabsContent>
<TabsContent value="analytics">
<Card>
<CardHeader>
<CardTitle>Analytics</CardTitle>
<CardDescription>
Track performance and user engagement metrics. Monitor trends and
identify growth opportunities.
</CardDescription>
</CardHeader>
<CardContent class="text-sm text-muted-foreground">
Page views are up 25% compared to last month.
</CardContent>
</Card>
</TabsContent>
<TabsContent value="reports">
<Card>
<CardHeader>
<CardTitle>Reports</CardTitle>
<CardDescription>
Generate and download your detailed reports. Export data in
multiple formats for analysis.
</CardDescription>
</CardHeader>
<CardContent class="text-sm text-muted-foreground">
You have 5 reports ready and available to export.
</CardContent>
</Card>
</TabsContent>
<TabsContent value="settings">
<Card>
<CardHeader>
<CardTitle>Settings</CardTitle>
<CardDescription>
Manage your account preferences and options. Customize your
experience to fit your needs.
</CardDescription>
</CardHeader>
<CardContent class="text-sm text-muted-foreground">
Configure notifications, security, and themes.
</CardContent>
</Card>
</TabsContent>
</Tabs>
)
}Installation
Install the following dependencies:
Copy and paste the following code into your project.
import { type ComponentProps } from "@solidjs/web"
import {
Tabs as SdkTabs,
TabsList as SdkTabsList,
TabsTab as SdkTabsTab,
TabsPanel as SdkTabsPanel
} from "@ui-sdk/solid/tabs"
import { cva, type VariantProps } from "class-variance-authority"
import { omit } from "solid-js"
import { cn } from "~/lib/utils"
type TabsProps = Omit<ComponentProps<typeof SdkTabs>, "class"> & {
class?: string
}
const Tabs = (props: TabsProps) => {
const others = omit(props, "class", "orientation")
return (
<SdkTabs
data-orientation={props.orientation ?? "horizontal"}
orientation={props.orientation ?? "horizontal"}
class={cn(
"group/tabs gap-2 flex data-[orientation=horizontal]:flex-col",
props.class
)}
{...others}
/>
)
}
const tabsListVariants = cva(
"group/tabs-list rounded-lg p-[3px] group-data-horizontal/tabs:h-8 data-[variant=line]:rounded-none inline-flex w-fit items-center justify-center text-muted-foreground group-data-[orientation=vertical]/tabs:h-fit group-data-[orientation=vertical]/tabs:flex-col",
{
variants: {
variant: {
default: "bg-muted",
line: "gap-1 bg-transparent"
}
},
defaultVariants: {
variant: "default"
}
}
)
type TabsListProps = (Omit<ComponentProps<typeof SdkTabsList>, "class"> & {
class?: string
}) &
VariantProps<typeof tabsListVariants>
const TabsList = (props: TabsListProps) => {
const others = omit(props, "variant", "class")
const variant = () => props.variant ?? "default"
return (
<SdkTabsList
class={cn(tabsListVariants({ variant: variant() }), props.class)}
data-variant={variant()}
{...others}
/>
)
}
type TabTriggerProps = Omit<ComponentProps<typeof SdkTabsTab>, "class"> & {
class?: string
}
const TabsTrigger = (props: TabTriggerProps) => (
<SdkTabsTab
{...props}
class={cn(
"gap-1.5 rounded-md border border-transparent px-1.5 py-0.5 text-sm font-medium has-data-[icon=inline-end]:pr-1 has-data-[icon=inline-start]:pl-1 group-data-[variant=default]/tabs-list:data-[selected]:shadow-sm group-data-[variant=line]/tabs-list:data-[selected]:shadow-none [&_svg:not([class*='size-'])]:size-4 relative inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center whitespace-nowrap text-foreground/60 transition-all group-data-[orientation=vertical]/tabs:w-full group-data-[orientation=vertical]/tabs:justify-start hover:text-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-1 focus-visible:outline-ring disabled:pointer-events-none disabled:opacity-50 dark:text-muted-foreground dark:hover:text-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0",
"group-data-[variant=line]/tabs-list:bg-transparent group-data-[variant=line]/tabs-list:data-[selected]:bg-transparent dark:group-data-[variant=line]/tabs-list:data-[selected]:border-transparent dark:group-data-[variant=line]/tabs-list:data-[selected]:bg-transparent",
"data-[selected]:bg-background data-[selected]:text-foreground dark:data-[selected]:border-input dark:data-[selected]:bg-input/30 dark:data-[selected]:text-foreground",
"after:absolute after:bg-foreground after:opacity-0 after:transition-opacity group-data-[orientation=horizontal]/tabs:after:inset-x-0 group-data-[orientation=horizontal]/tabs:after:-bottom-1.25 group-data-[orientation=horizontal]/tabs:after:h-0.5 group-data-[orientation=vertical]/tabs:after:inset-y-0 group-data-[orientation=vertical]/tabs:after:-right-1 group-data-[orientation=vertical]/tabs:after:w-0.5 group-data-[variant=line]/tabs-list:data-[selected]:after:opacity-100",
props.class
)}
/>
)
type TabsContentProps = Omit<ComponentProps<typeof SdkTabsPanel>, "class"> & {
class?: string
}
const TabsContent = (props: TabsContentProps) => (
<SdkTabsPanel
{...props}
class={cn("text-sm flex-1 outline-none", props.class)}
/>
)
export { Tabs, TabsContent, TabsList, tabsListVariants, TabsTrigger }Update the import paths to match your project setup.
Usage
import { Tabs, TabsContent, TabsList, TabsTrigger } from "~/components/ui/tabs"<Tabs defaultValue="account" class="w-[400px]">
<TabsList>
<TabsTrigger value="account">Account</TabsTrigger>
<TabsTrigger value="password">Password</TabsTrigger>
</TabsList>
<TabsContent value="account">Make changes to your account here.</TabsContent>
<TabsContent value="password">Change your password here.</TabsContent>
</Tabs>Composition
Use the following composition to build Tabs:
Tabs
├── TabsList
│ ├── TabsTrigger
│ └── TabsTrigger
├── TabsContent
└── TabsContentLine
Use the variant="line" prop on TabsList for a line style.
import { Tabs, TabsList, TabsTrigger } from "~/components/ui/tabs"
export default function TabsLine() {
return (
<Tabs defaultValue="overview">
<TabsList variant="line">
<TabsTrigger value="overview">Overview</TabsTrigger>
<TabsTrigger value="analytics">Analytics</TabsTrigger>
<TabsTrigger value="reports">Reports</TabsTrigger>
</TabsList>
</Tabs>
)
}Vertical
Use orientation="vertical" for vertical tabs.
import { Tabs, TabsList, TabsTrigger } from "~/components/ui/tabs"
export default function TabsVertical() {
return (
<Tabs defaultValue="account" orientation="vertical">
<TabsList>
<TabsTrigger value="account">Account</TabsTrigger>
<TabsTrigger value="password">Password</TabsTrigger>
<TabsTrigger value="notifications">Notifications</TabsTrigger>
</TabsList>
</Tabs>
)
}Disabled
import { Tabs, TabsList, TabsTrigger } from "~/components/ui/tabs"
export default function TabsDisabled() {
return (
<Tabs defaultValue="home">
<TabsList>
<TabsTrigger value="home">Home</TabsTrigger>
<TabsTrigger value="settings" disabled>
Disabled
</TabsTrigger>
</TabsList>
</Tabs>
)
}Icons
// Inline SVG icons from Lucide (https://lucide.dev), ISC License, Copyright (c) Lucide Icons and Contributors.
import { Tabs, TabsList, TabsTrigger } from "~/components/ui/tabs"
export default function TabsIcons() {
return (
<Tabs defaultValue="preview">
<TabsList>
<TabsTrigger value="preview">
<svg
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
class="size-4"
>
<path d="m21 21-4.34-4.34" />
<circle cx="11" cy="11" r="8" />
</svg>
Preview
</TabsTrigger>
<TabsTrigger value="code">
<svg
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
class="size-4"
>
<path d="m16 18 6-6-6-6" />
<path d="m8 6-6 6 6 6" />
</svg>
Code
</TabsTrigger>
</TabsList>
</Tabs>
)
}API Reference
See the UI SDK documentation for more information.