Tabs for Astro
Astro tab panels with pill, inset-outline, and underline variants.
Installation
bunx --bun shadcn@latest add @gnostic/tabsnpx shadcn@latest add @gnostic/tabspnpm dlx shadcn@latest add @gnostic/tabsInstall component packages
bun add @data-slot/tabsnpm install @data-slot/tabspnpm add @data-slot/tabsCopy the files
src/components/ui/tabs/index.tssrc/components/ui/tabs/tabs-content.astrosrc/components/ui/tabs/tabs-list-variants.tssrc/components/ui/tabs/tabs-list.astrosrc/components/ui/tabs/tabs-trigger.astrosrc/components/ui/tabs/tabs.astrosrc/components/ui/tabs/types.ts
Usage
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"
<Tabs defaultValue="tab-1">
<TabsList>
<TabsTrigger value="tab-1">Tab 1</TabsTrigger>
<TabsTrigger value="tab-2">Tab 2</TabsTrigger>
</TabsList>
<TabsContent value="tab-1"> Content for tab 1 </TabsContent>
<TabsContent value="tab-2"> Content for tab 2 </TabsContent>
</Tabs>
Composition
Use the following composition to build Tabs:
Tabs
├── TabsList
│ ├── TabsTrigger
│ └── TabsTrigger
├── TabsContent
└── TabsContent
Examples
Inset outline
Set variant="inset-outline" on TabsList for a secondary background and a thin ring around the active tab.
Underline
Use variant="underline" on TabsList for a line under the active tab.
Small
size on TabsList sets the size of every tab. Use sm, default, or lg.
Vertical
Use orientation="vertical" for side navigation patterns.
Disabled
Grid
RTL
Set dir="rtl" on the document or the relevant region. Check text order, focus, and directional icons in the rendered Astro page. No React provider is required.
API Reference
Read the installed source for the complete prop types. See the data-slot docs for more information on interactivity.
Events
Dispatch these events on the tabs root. The root emits the outbound events.
Outbound events
| Event | Detail |
|---|---|
tabs:change |
{ value: string } |
Inbound events
| Event | Detail |
|---|---|
tabs:set |
{ value: string } |
When to use Tabs
Use Tabs for peer views of the same subject. Give each trigger a stable value that matches one content panel. Use the existing list variant and size props to fit the page design.
Keyboard and behavior
The data-slot controller manages selected state and keyboard movement. Test orientation, disabled triggers, and focus after changing panels. Tabs switch local content; use links when each destination has its own route.
Theme and layout
The indicator reads size and position from controller variables. Long labels need a narrow-screen layout check. Keep vertical lists wide enough for readable text and test the selected preset at each supported size.