Tabs Primitive
Tabs is a Starwind Runtime primitive in the controlled-value-group contract family. Astro and React share one semantic component API. React coordinates reactive state through controlled and default props plus callbacks. Astro renders initial state and coordinates later changes through DOM events and Runtime methods. Raw HTML uses Runtime attributes, DOM events, and imperative methods.
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> );}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
Runtime Setters
Related Styled Components
Changelog
View version history v1.0.0 3 releases
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.