Skip to main content

Starwind UI v3.0 beta is now available! Read the migration guide

Tabs Primitive

Tabs is a Starwind Runtime primitive in the controlled-value-group contract family.

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>

API Reference

Root

The main element that owns the Tabs Runtime instance.

Default element
div
Discovery hook
data-sw-tabs
Role
-

Props

Prop Type Default Toggle
value TabsValue -
Description
Controls the current Tabs value.
Kind
control
Targets
root
Full type
TabsValue
defaultValue TabsValue -
Description
Sets the initial Tabs value for uncontrolled usage.
Kind
control
Targets
-
Full type
TabsValue
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

Events

Event Callback Value Toggle
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

State

State Type Props Toggle
value TabsValue value / defaultValue
Description
Tracks the current Tabs value.
Initial attribute
data-default-value
Runtime getter
getValue
Runtime setter
setValue
State control support
React supports controlled and default state with value and defaultValue props. Runtime/HTML reads initial state from data-default-value, emits starwind:value-change, and updates with setValue. Astro adapters render initial/default state, but do not expose reactive controlled-state props for this state.

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-tabs - Marks the Root part so Starwind Runtime can find it.
State
Attribute Value Description
data-value - Reflects the value state on the Root part.
Metadata
Attribute Value Description
data-default-value - Reflects the default value prop on the Root part.
data-orientation - Reflects the orientation prop on the Root part.
data-sync-key - Reflects the sync key prop on the Root part.

List

The list of selectable Tabs items.

Default element
div
Discovery hook
data-sw-tabs-list
Role
tablist

Props

Prop Type Default Toggle
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
Attribute Value Description
data-sw-tabs-list - Marks the List part so Starwind Runtime can find it.
Metadata
Attribute Value Description
data-activate-on-focus - Reflects the activate on focus prop on the List part.
data-loop-focus - Reflects the loop focus prop on the List part.
data-orientation - Reflects the orientation prop on the List part.

Tab

A selectable tab inside Tabs.

Default element
button
Discovery hook
data-sw-tabs-tab
Role
tab

Props

Prop Type Default Toggle
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

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-tabs-tab - Marks the Tab part so Starwind Runtime can find it.
State
Attribute Value Description
data-active - Reflects the active state on the Tab part.
data-orientation - Reflects the orientation state on the Tab part.
data-state - Reflects the current state on the Tab part.
Metadata
Attribute Value Description
data-disabled - Reflects the disabled prop on the Tab part.
data-value - Reflects the value prop on the Tab part.

Panel

The content panel controlled by Tabs.

Default element
div
Discovery hook
data-sw-tabs-panel
Role
tabpanel

Props

Prop Type Default Toggle
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

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-tabs-panel - Marks the Panel part so Starwind Runtime can find it.
State
Attribute Value Description
data-active - Reflects the active state on the Panel part.
data-orientation - Reflects the orientation state on the Panel part.
data-state - Reflects the current state on the Panel part.
Metadata
Attribute Value Description
data-keep-mounted - Reflects the keep mounted prop on the Panel part.
data-value - Reflects the value prop on the Panel part.

Indicator

Visual state indicator rendered by Tabs.

Default element
span
Discovery hook
data-sw-tabs-indicator
Role
presentation

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-tabs-indicator - Marks the Indicator part so Starwind Runtime can find it.
State
Attribute Value Description
data-orientation - Reflects the orientation state on the Indicator part.

Runtime API

Factory
createTabs
Import
@starwind-ui/runtime/tabs
Root hook
root data-sw-tabs
Option props
defaultValue, orientation, syncKey, value

Runtime Setters

Method Target Description
setValue state: value Updates the current Tabs value from Runtime code.
Component Relationship
Tabs Direct primitive