Skip to main content

Starwind UI v3.0 is now available! Migration guide

Build fast websites, faster with Astro’s next-gen island architecture.

The React framework for production-grade applications that scale.

Installation

Usage

---
import { Tabs, TabsList, TabsTrigger, TabsContent } from "@/components/starwind/tabs";
---
<Tabs defaultValue="astro" class="max-w-[400px]">
<TabsList>
<TabsTrigger value="astro">Astro</TabsTrigger>
<TabsTrigger value="next">Next.js</TabsTrigger>
</TabsList>
<TabsContent value="astro">
Build fast websites, faster with Astro's next-gen island architecture.
</TabsContent>
<TabsContent value="next">
The React framework for production-grade applications that scale.
</TabsContent>
</Tabs>

Composition

Match each trigger value to one content value:

Tabs
├── TabsList
│ ├── TabsTrigger
│ └── TabsTrigger
├── TabsContent
└── TabsContent

Synced Tabs

Use the syncKey prop to synchronize multiple tab groups. All tabs with the same syncKey will update together.

React is a JavaScript library for building user interfaces.

Vue is a progressive framework for building user interfaces.

React’s virtual DOM optimizes rendering performance.

Vue’s reactivity system makes state management intuitive.

Disabled Triggers

Use the disabled attribute to prevent a tab from being selected.

Active tab content
Disabled tab content
Pending tab content

Nested Tabs

Show how tabs can be nested by placing a Tabs component inside a TabsContent panel.

Outer Tab 1 content

This tab contains nested tabs:

Inner tab A content
Inner tab B content

Animated Panels

Place panels in the same grid cell and add an opacity transition. Tabs exposes data-starting-style on an entering panel and data-ending-style on an exiting panel. The outgoing panel stays visible until its transition finishes, then receives hidden.

Inactive panels are inert, so their links and controls cannot receive input during the fade. Use motion-reduce:transition-none to respect reduced-motion preferences. keepMounted preserves mounted content; it does not make inactive panels permanently visible.

Your workspace is ready.

Set up a component

Review recent changes in your workspace.

Read the changelog

When code changes the selected tab, the next Tab-key entry follows the selected enabled trigger. If focus is already in the tab list, Tabs preserves the user’s keyboard position. Selection changes do not move focus from elsewhere on the page.

API Reference

Styled Component API

These props are added or materially changed by the installed styled component. Standard HTML attributes remain available through the inherited interfaces noted below. Expand a prop to see named type definitions and framework-specific imports. Follow the Primitive and Runtime links for lower-level behavior props.

Tabs

Inherits div attributes. Omits `defaultValue`, `onChange`, and `value`.

Contains the following additional props:

Prop Type Default Toggle details
defaultValue string | null —
Description
Sets the initial value when the component is uncontrolled.
Classification
Primitive override
Type imports
React import type { TabsValue } from "@starwind-ui/react";
Primitive prop
tabs.Root.defaultValue
orientation "horizontal" | "vertical" "horizontal"
Description
Selects the horizontal or vertical layout direction.
Classification
Primitive override
Primitive prop
tabs.Root.orientation
value string | null —
Description
Controls or identifies the component value.
Classification
Primitive override
Type imports
React import type { TabsValue } from "@starwind-ui/react";
Primitive prop
tabs.Root.value

Tabs List

Inherits div attributes.

Contains the following additional props:

Prop Type Default Toggle details
activateOnFocus boolean —
Description
Activates the focused item while moving through the collection.
Classification
Primitive override
Primitive prop
tabs.List.activateOnFocus
loopFocus boolean —
Description
Wraps keyboard focus from the last item to the first and vice versa.
Classification
Primitive override
Primitive prop
tabs.List.loopFocus

Tabs Trigger

Inherits button attributes. Omits `type` and `value`.

Contains the following additional props:

Prop Type Default Toggle details
value Required string —
Description
Controls or identifies the component value.
Classification
Wrapper prop

Tabs Content

Inherits div attributes.

Contains the following additional props:

Prop Type Default Toggle details
keepMounted boolean —
Description
Keeps hidden content mounted in the DOM.
Classification
Primitive override
Primitive prop
tabs.Panel.keepMounted
value Required string —
Description
Controls or identifies the component value.
Classification
Wrapper prop

Primitive And Runtime API

Use these references when you need the lower-level behavior APIs behind Tabs.

Primitive API

Runtime API

Tabs primitive
createTabs from @starwind-ui/runtime/tabs

Changelog

View version history v2.2.0 12 releases

v2.2.0

  • In Svelte, a defined value that you pass when Tabs mounts now stays under your control, as in React and Vue. To change it, use bind: or update your state in the change callback. A form reset keeps it. If you pass undefined at mount, Tabs keeps its own state.
  • In Vue, a Boolean prop that you leave out, such as activateOnFocus, loopFocus, or keepMounted, no longer becomes false. The default of the underlying component applies.

v2.1.0

  • Vue Tabs keeps the selected tab when a selection change is canceled.
  • Tabs keeps its initial syncKey while mounted. Remount it to change that key.
  • Added CSS entrance and exit animations using data-starting-style and data-ending-style. Panels stay visible until their exit animation finishes, while inactive content stops accepting keyboard focus and clicks.
  • When your code selects a tab, pressing Tab to enter the tab list now focuses that tab. Focus stays in place while someone is already navigating the list.

v2.0.2

  • Fixed the active tab indicator position when its container is scrolled or transformed.

v2.0.1

  • The default export in index.ts now has a name, TabsParts, so framework tools show a clear name.

v2.0.0

  • Tabs now gets its behavior from Starwind Runtime. Runtime handles selection, focus movement, and groups of tabs that stay in sync.
  • See the Tabs Primitive for the unstyled parts and the behavior API.

v1.4.3

  • The Tailwind variants now live in their own variants.ts file in the component folder.

v1.4.1

  • Add starwind:init event listener to enable initialization of additional Tabs loaded after an initial page load, such as when using server islands

v1.4.0

  • style and focus state updates

v1.3.0

  • Add a data-slot attribute to all components to enable global styling updates

v1.2.0

  • Add support for nested tabs

v1.1.1

  • Small script cleanup

v1.1.0

  • tailwind-variants now implemented. This uses tailwind-merge under the hood to merge Tailwind classes without style conflicts, allowing you to override any existing classes using the “class” prop.