Tabs Primitive
Tabs is a Starwind Runtime primitive in the controlled-value-group contract family. Astro, React, Vue, and Svelte components use the same underlying interactions. Each framework has its own way to read and update state. See the examples and your installed packageโs types for the available props and events. Plain HTML uses DOM events and Runtime methods.
Usage Guidelines
- Animate panel changes with CSS. Apply transitions or keyframe animations to the panel. Use
data-starting-stylefor its entrance anddata-ending-stylefor its exit. Initial panels appear without an entrance animation. The animated Styled Tabs example shows a crossfade with reduced-motion support. - Keep visibility under Runtime control. An outgoing panel becomes
inertimmediately, then receiveshiddenwhen its own finite motion finishes. Its controls cannot receive input during the exit. Descendant motion and infinite animations do not delay hiding. Panel DOM and local state remain mounted;keepMountedpreserves its existing behavior. - Keep keyboard entry aligned with selection. When code changes the selected tab while focus is outside the tab list, the selected enabled trigger becomes the next keyboard entry target. Browser focus stays where it is. While focus is inside the list, Tabs preserves the userโs keyboard position.
Anatomy
Use the Astro primitive adapter to render Tabs anatomy with the Runtime wiring included.
---import { Tabs } from "@starwind-ui/astro/tabs";---
<Tabs.Root defaultValue="account"> <Tabs.List> <Tabs.Tab value="account">Account</Tabs.Tab> </Tabs.List> <Tabs.Panel value="account">Account settings</Tabs.Panel></Tabs.Root>Use the React primitive adapter when Tabs state participates in React rendering.
import { Tabs } from "@starwind-ui/react/tabs";
export function Example() { return ( <Tabs.Root defaultValue="account"> <Tabs.List> <Tabs.Tab value="account">Account</Tabs.Tab> </Tabs.List> <Tabs.Panel value="account">Account settings</Tabs.Panel> </Tabs.Root> );}Use the Vue components to build Tabs.
<script setup lang="ts">import Tabs from "@starwind-ui/vue/tabs";</script>
<template> <Tabs.Root defaultValue="account"> <Tabs.List> <Tabs.Tab value="account">Account</Tabs.Tab> </Tabs.List> <Tabs.Panel value="account">Account settings</Tabs.Panel> </Tabs.Root></template>Render the Tabs data-sw-* contract yourself, then initialize createTabs.
<div data-sw-tabs data-default-value="account"> <div data-sw-tabs-list role="tablist"> <button data-sw-tabs-tab role="tab" type="button" data-value="account">Account</button> </div> <div data-sw-tabs-panel role="tabpanel" hidden data-value="account">Account settings</div></div>
<script type="module"> import { createTabs } from "@starwind-ui/runtime/tabs";
const root = document.querySelector("[data-sw-tabs]"); if (root) { createTabs(root); }</script>API Reference
Root
The main element that owns the Tabs Runtime instance.
- Default element
- div
- Discovery hook
- data-sw-tabs
- Role
- -
Props
value TabsValue -
- Description
- Controls the current Tabs value.
- Kind
- control
- Targets
- root
- Full type
- TabsValue
- React
Use value for controlled state and defaultValue for default state, and onValueChange for change proposals.
valuedefaultValueonValueChange
- Astro
Use value or defaultValue for initial state, listen for starwind:value-change, and call setValue for later updates.
valuedefaultValuestarwind:value-changesetValue
- Runtime / HTML
Use data-default-value for initial state, listen for starwind:value-change, and call setValue for later updates.
data-default-valuestarwind:value-changesetValue
defaultValue TabsValue -
- Description
- Sets the initial Tabs value for uncontrolled usage.
- Kind
- control
- Targets
- -
- Full type
- TabsValue
- React
Use value for controlled state and defaultValue for default state, and onValueChange for change proposals.
valuedefaultValueonValueChange
- Astro
Use value or defaultValue for initial state, listen for starwind:value-change, and call setValue for later updates.
valuedefaultValuestarwind:value-changesetValue
- Runtime / HTML
Use data-default-value for initial state, listen for starwind:value-change, and call setValue for later updates.
data-default-valuestarwind:value-changesetValue
orientation TabsOrientation "horizontal"
- Description
- Sets the Tabs orientation.
- Kind
- option
- Targets
- -
- Full type
- TabsOrientation
syncKey string -
- Description
- Configures the sync key option for the Root part.
- Kind
- option
- Targets
- -
- Full type
- string
onValueChange (value: TabsValue, details: TabsValueChangeDetails) => void -
- Description
- Runs when the Tabs value changes.
- Kind
- callback
- Targets
- -
- Full type
- (value: TabsValue, details: TabsValueChangeDetails) => void
- React
Use value for controlled state and defaultValue for default state, and onValueChange for change proposals.
valuedefaultValueonValueChange
- Astro
Use value or defaultValue for initial state, listen for starwind:value-change, and call setValue for later updates.
valuedefaultValuestarwind:value-changesetValue
- Runtime / HTML
Use data-default-value for initial state, listen for starwind:value-change, and call setValue for later updates.
data-default-valuestarwind:value-changesetValue
Events
valueChange onValueChange value: TabsValue
- Description
- Fires when the value changes for Tabs.
- DOM event
- starwind:value-change
- Details type
- TabsValueChangeDetails
- Timing
- before-state-commit
- Cancelable
- Yes
- Cancellation sequence
- Check internal eligibility and intent.
- Create one details object for the proposal.
- Call the Runtime callback with the details object when the controller exposes one.
- Dispatch the cancelable DOM event with the same details object, including when the callback canceled it.
- Read details.isCanceled, including cancellation caused by preventDefault().
- Apply the accepted state.
- Notify Runtime subscribers and other accepted-only observers.
State
value TabsValue value / defaultValue
- Description
- Tracks the current Tabs value.
- Initial attribute
- data-default-value
- Runtime getter
- getValue
- Runtime setter
- setValue
- React
Use value for controlled state and defaultValue for default state, and onValueChange for change proposals.
valuedefaultValueonValueChange
- Astro
Use value or defaultValue for initial state, listen for starwind:value-change, and call setValue for later updates.
valuedefaultValuestarwind:value-changesetValue
- Runtime / HTML
Use data-default-value for initial state, listen for starwind:value-change, and call setValue for later updates.
data-default-valuestarwind:value-changesetValue
Data Attributes
Runtime hooks
State
Metadata
List
The list of selectable Tabs items.
- Default element
- div
- Discovery hook
- data-sw-tabs-list
- Role
- tablist
Props
activateOnFocus boolean false
- Description
- Configures the activate on focus option for the List part.
- Kind
- option
- Targets
- list
- Full type
- boolean
loopFocus boolean true
- Description
- Lets keyboard focus wrap around the Tabs items.
- Kind
- option
- Targets
- list
- Full type
- boolean
Data Attributes
Runtime hooks
Metadata
Tab
A selectable tab inside Tabs.
- Default element
- button
- Discovery hook
- data-sw-tabs-tab
- Role
- tab
Props
disabled boolean false
- Description
- Disables the Tab part.
- Kind
- option
- Targets
- tab
- Full type
- boolean
value string -
- Description
- Controls the current Tabs value.
- Kind
- option
- Targets
- tab
- Full type
- string
- React
Use value for controlled state and defaultValue for default state, and onValueChange for change proposals.
valuedefaultValueonValueChange
- Astro
Use value or defaultValue for initial state, listen for starwind:value-change, and call setValue for later updates.
valuedefaultValuestarwind:value-changesetValue
- Runtime / HTML
Use data-default-value for initial state, listen for starwind:value-change, and call setValue for later updates.
data-default-valuestarwind:value-changesetValue
Data Attributes
Runtime hooks
State
Metadata
Panel
The content panel controlled by Tabs.
- Default element
- div
- Discovery hook
- data-sw-tabs-panel
- Role
- tabpanel
Props
keepMounted boolean false
- Description
- Keeps the Panel part in the DOM when hidden.
- Kind
- rendering
- Targets
- panel
- Full type
- boolean
value string -
- Description
- Controls the current Tabs value.
- Kind
- option
- Targets
- panel
- Full type
- string
- React
Use value for controlled state and defaultValue for default state, and onValueChange for change proposals.
valuedefaultValueonValueChange
- Astro
Use value or defaultValue for initial state, listen for starwind:value-change, and call setValue for later updates.
valuedefaultValuestarwind:value-changesetValue
- Runtime / HTML
Use data-default-value for initial state, listen for starwind:value-change, and call setValue for later updates.
data-default-valuestarwind:value-changesetValue
Data Attributes
Runtime hooks
State
Metadata
Indicator
Visual state indicator rendered by Tabs.
- Default element
- span
- Discovery hook
- data-sw-tabs-indicator
- Role
- presentation
Data Attributes
Runtime hooks
State
Runtime API
- Factory
createTabs- Import
@starwind-ui/runtime/tabs- Root hook
- root
data-sw-tabs - Option props
- defaultValue, orientation, syncKey, value
Option Lifecycles
| Option | Lifecycle |
|---|---|
| syncKey | constructor-only |
Runtime Setters
Related Styled Components
Changelog
View version history v1.1.0 5 releases
v1.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.
- Reduced repeated JavaScript when Astro Tabs is used with other Starwind components.
v1.0.1
- Removed obsolete private-release warnings from generated Vue adapters and normalized the resulting blank line in vendored Primitive indexes.
- Measured the active tab indicator in local layout coordinates so scrolling and transforms preserve its alignment.
v1.0.0
- Promoted this Primitive's vendoring version to the stable 1.0.0 baseline. Its existing API and Runtime behavior carry forward from the previous release.
v0.1.1
- Marked generated React Primitive files as client modules so vendored installs preserve client boundaries in React server frameworks.
v0.1.0
- Introduced tab selection, roving focus, panel presence, orientation, and synchronized groups.