Select Primitive
Select is a Starwind Runtime primitive in the floating-value-control contract family.
Anatomy
Use the Astro primitive adapter to render Select anatomy with the Runtime wiring included.
---import { Select } from "@starwind-ui/astro/select";---
<Select.Root> <Select.Label>Choose a framework</Select.Label> <Select.Trigger> <Select.Value>Astro</Select.Value> <Select.Icon>v</Select.Icon> </Select.Trigger> <Select.Positioner> <Select.Popup /> </Select.Positioner></Select.Root>Use the React primitive adapter when Select state participates in React rendering.
import { Select } from "@starwind-ui/react/select";
export function Example() { return ( <Select.Root> <Select.Label>Choose a framework</Select.Label> <Select.Trigger> <Select.Value>Astro</Select.Value> <Select.Icon>v</Select.Icon> </Select.Trigger> <Select.Positioner> <Select.Popup /> </Select.Positioner> </Select.Root> );}Render the Select data-sw-* contract yourself, then initialize createSelect.
<div data-sw-select> <div data-sw-select-label>Choose a framework</div> <button data-sw-select-trigger role="combobox" aria-haspopup="listbox"> <span data-sw-select-value>Astro</span> <span data-sw-select-icon aria-hidden="true">v</span> </button> <div data-sw-select-positioner> <div data-sw-select-popup role="listbox" hidden tabindex="-1"> <div data-sw-select-list> <div data-sw-select-item role="option" data-value="astro"> <span data-sw-select-item-text>Astro</span> <span data-sw-select-item-indicator aria-hidden="true" hidden></span> </div> </div> </div> </div></div>
<script type="module"> import { createSelect } from "@starwind-ui/runtime/select";
const root = document.querySelector("[data-sw-select]"); if (root) { createSelect(root); }</script>Positioning
Select positions its popup from the trigger. Keep the Positioner and Popup parts near the trigger in source order so the relationship stays readable, then let the Runtime handle placement, collision, and open-state updates after hydration.
Examples
Positioned Select
Render Select with a positioned popup across Astro, React, and HTML surfaces.
---import { Select } from "@starwind-ui/astro/select";---
<Select.Root defaultValue="astro"> <Select.Label>Framework</Select.Label> <Select.Trigger> <Select.Value>Astro</Select.Value> <Select.Icon>v</Select.Icon> </Select.Trigger> <Select.Positioner> <Select.Popup> <Select.List> <Select.Item value="astro"> <Select.ItemText>Astro</Select.ItemText> <Select.ItemIndicator /> </Select.Item> <Select.Item value="react"> <Select.ItemText>React</Select.ItemText> <Select.ItemIndicator /> </Select.Item> </Select.List> </Select.Popup> </Select.Positioner></Select.Root>import { Select } from "@starwind-ui/react/select";
export function Example() { return ( <Select.Root defaultValue="astro"> <Select.Label>Framework</Select.Label> <Select.Trigger> <Select.Value>Astro</Select.Value> <Select.Icon>v</Select.Icon> </Select.Trigger> <Select.Positioner> <Select.Popup> <Select.List> <Select.Item value="astro"> <Select.ItemText>Astro</Select.ItemText> <Select.ItemIndicator /> </Select.Item> <Select.Item value="react"> <Select.ItemText>React</Select.ItemText> <Select.ItemIndicator /> </Select.Item> </Select.List> </Select.Popup> </Select.Positioner> </Select.Root> );}<div data-sw-select data-default-value="astro"> <span data-sw-select-label>Framework</span> <button data-sw-select-trigger type="button"> <span data-sw-select-value>Astro</span> <span data-sw-select-icon>v</span> </button> <div data-sw-select-positioner> <div data-sw-select-popup> <div data-sw-select-list> <div data-sw-select-item data-value="astro"> <span data-sw-select-item-text>Astro</span> <span data-sw-select-item-indicator></span> </div> <div data-sw-select-item data-value="react"> <span data-sw-select-item-text>React</span> <span data-sw-select-item-indicator></span> </div> </div> </div> </div></div>
<script type="module"> import { createSelect } from "@starwind-ui/runtime/select";
const root = document.querySelector("[data-sw-select]"); if (root) { createSelect(root); }</script>Floating Behavior
| Fact | Value |
|---|---|
| Anchor part | trigger |
| Positioner part | positioner |
| Popup part | popup |
| Portal part | portal |
| Option props | side, align, sideOffset, alignOffset, avoidCollisions, alignItemWithTrigger |
API Reference
Root
The main element that owns the Select Runtime instance.
- Default element
- div
- Discovery hook
- data-sw-select
- Role
- -
Props
open boolean -
- Description
- Controls whether Select is open.
- Kind
- control
- Targets
- -
- Full type
- boolean
defaultOpen boolean -
- Description
- Sets whether Select starts open.
- Kind
- control
- Targets
- -
- Full type
- boolean
value string | null -
- Description
- Controls the current Select value.
- Kind
- control
- Targets
- -
- Full type
- string | null
defaultValue string | null -
- Description
- Sets the initial Select value for uncontrolled usage.
- Kind
- control
- Targets
- -
- Full type
- string | null
autoComplete string -
- Description
- Sets the native autocomplete behavior.
- Kind
- option
- Targets
- -
- Full type
- string
disabled boolean -
- Description
- Disables the Root part.
- Kind
- option
- Targets
- -
- Full type
- boolean
form string -
- Description
- Associates the control with a form element.
- Kind
- option
- Targets
- -
- Full type
- string
highlightItemOnHover boolean true
- Description
- Highlights Select items when the pointer moves over them.
- Kind
- option
- Targets
- -
- Full type
- boolean
modal boolean true
- Description
- Makes Select behave as a modal overlay.
- Kind
- option
- Targets
- root
- Full type
- boolean
name string -
- Description
- Sets the submitted form field name.
- Kind
- option
- Targets
- -
- Full type
- string
readOnly boolean false
- Description
- Marks the control as read-only.
- Kind
- option
- Targets
- -
- Full type
- boolean
required boolean -
- Description
- Marks the form control as required.
- Kind
- option
- Targets
- -
- Full type
- boolean
onOpenChange (open: unknown, details: SelectOpenChangeDetails) => void -
- Description
- Runs when Select opens or closes.
- Kind
- callback
- Targets
- -
- Full type
- (open: unknown, details: SelectOpenChangeDetails) => void
onValueChange (value: unknown, details: SelectValueChangeDetails) => void -
- Description
- Runs when the Select value changes.
- Kind
- callback
- Targets
- -
- Full type
- (value: unknown, details: SelectValueChangeDetails) => void
Events
openChange onOpenChange open
- Description
- Fires when Select opens or closes.
- DOM event
- starwind:open-change
- Details type
- SelectOpenChangeDetails
- Timing
- -
- Cancelable
- No
valueChange onValueChange value
- Description
- Fires when the value changes for Select.
- DOM event
- starwind:value-change
- Details type
- SelectValueChangeDetails
- Timing
- -
- Cancelable
- No
State
open boolean open / defaultOpen
- Description
- Tracks whether Select is open.
- Initial attribute
- data-default-open
- Runtime getter
- getOpen
- Runtime setter
- setOpen
- State control support
- React supports controlled and default state with open and defaultOpen props. Runtime/HTML reads initial state from data-default-open, emits starwind:open-change, and updates with setOpen. Astro adapters render initial/default state, but do not expose reactive controlled-state props for this state.
value string | null value / defaultValue
- Description
- Tracks the current Select 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
State
Metadata
Label
Text label associated with Select.
- Default element
- div
- Discovery hook
- data-sw-select-label
- Role
- -
Data Attributes
Runtime hooks
Trigger
The control that opens, closes, or targets the Select content.
- Default element
- button
- Discovery hook
- data-sw-select-trigger
- Role
- combobox
Props
asChild boolean -
- Description
- Merges behavior onto your child element instead of rendering the default Trigger element.
- Kind
- rendering
- Targets
- trigger
- Full type
- boolean
Data Attributes
Runtime hooks
State
Metadata
Value
Displays the current Select value.
- Default element
- span
- Discovery hook
- data-sw-select-value
- Role
- -
Data Attributes
Runtime hooks
Icon
Decorative icon rendered by Select.
- Default element
- span
- Discovery hook
- data-sw-select-icon
- Role
- -
Data Attributes
Runtime hooks
Input
The native input synchronized by Select.
- Default element
- input
- Discovery hook
- data-sw-select-input
- Role
- -
Data Attributes
Runtime hooks
Portal
Moves Select overlay content to the document body when needed.
- Default element
- div
- Discovery hook
- data-sw-select-portal
- Role
- -
Data Attributes
Runtime hooks
Positioner
Positions the Select content relative to its trigger.
- Default element
- div
- Discovery hook
- data-sw-select-positioner
- Role
- -
Props
side "top" | "right" | "bottom" | "left" "bottom"
- Description
- Sets the preferred side for Select content.
- Kind
- option
- Targets
- positioner, popup
- Full type
- "top" | "right" | "bottom" | "left"
align "start" | "center" | "end" "start"
- Description
- Sets how Select content aligns to its trigger.
- Kind
- option
- Targets
- positioner, popup
- Full type
- "start" | "center" | "end"
sideOffset number 4
- Description
- Sets the distance between Select content and its trigger.
- Kind
- option
- Targets
- positioner, popup
- Full type
- number
alignOffset number 0
- Description
- Adjusts the cross-axis alignment offset for Select content.
- Kind
- option
- Targets
- positioner, popup
- Full type
- number
avoidCollisions boolean true
- Description
- Allows Select content to shift or flip to stay visible.
- Kind
- option
- Targets
- positioner, popup
- Full type
- boolean
alignItemWithTrigger boolean true
- Description
- Configures the align item with trigger option for the Positioner part.
- Kind
- option
- Targets
- positioner
- Full type
- boolean
Data Attributes
Runtime hooks
Metadata
Popup
The floating content container for Select.
- Default element
- div
- Discovery hook
- data-sw-select-popup
- Role
- listbox
Props
side "top" | "right" | "bottom" | "left" "bottom"
- Description
- Sets the preferred side for Select content.
- Kind
- option
- Targets
- positioner, popup
- Full type
- "top" | "right" | "bottom" | "left"
align "start" | "center" | "end" "start"
- Description
- Sets how Select content aligns to its trigger.
- Kind
- option
- Targets
- positioner, popup
- Full type
- "start" | "center" | "end"
sideOffset number 4
- Description
- Sets the distance between Select content and its trigger.
- Kind
- option
- Targets
- positioner, popup
- Full type
- number
alignOffset number 0
- Description
- Adjusts the cross-axis alignment offset for Select content.
- Kind
- option
- Targets
- positioner, popup
- Full type
- number
avoidCollisions boolean true
- Description
- Allows Select content to shift or flip to stay visible.
- Kind
- option
- Targets
- positioner, popup
- Full type
- boolean
Data Attributes
Runtime hooks
State
Metadata
List
The list of selectable Select items.
- Default element
- div
- Discovery hook
- data-sw-select-list
- Role
- -
Data Attributes
Runtime hooks
Group
Groups related Select items.
- Default element
- div
- Discovery hook
- data-sw-select-group
- Role
- group
Data Attributes
Runtime hooks
Group Label
Labels a group of Select items.
- Default element
- div
- Discovery hook
- data-sw-select-group-label
- Role
- -
Data Attributes
Runtime hooks
Item
An interactive item inside the Select collection.
- Default element
- div
- Discovery hook
- data-sw-select-item
- Role
- option
Data Attributes
Runtime hooks
Metadata
Item Text
Text content for a Select item.
- Default element
- span
- Discovery hook
- data-sw-select-item-text
- Role
- -
Data Attributes
Runtime hooks
Item Indicator
Shows the selected state for a Select item.
- Default element
- span
- Discovery hook
- data-sw-select-item-indicator
- Role
- -
Data Attributes
Runtime hooks
State
Separator
Separates groups of Select items.
- Default element
- div
- Discovery hook
- data-sw-select-separator
- Role
- separator
Data Attributes
Runtime hooks
Scroll Up Arrow
Scrolls Select options upward.
- Default element
- div
- Discovery hook
- data-sw-select-scroll-up-arrow
- Role
- -
Data Attributes
Runtime hooks
Scroll Down Arrow
Scrolls Select options downward.
- Default element
- div
- Discovery hook
- data-sw-select-scroll-down-arrow
- Role
- -
Data Attributes
Runtime hooks
Runtime API
- Factory
createSelect- Import
@starwind-ui/runtime/select- Root hook
- root
data-sw-select - Option props
- autoComplete, defaultOpen, defaultValue, disabled, form, highlightItemOnHover, modal, open, readOnly, value
Option Lifecycles
| Option | Lifecycle |
|---|---|
| autoComplete | constructor-only |
| defaultOpen | constructor-only |
| defaultValue | constructor-only |
| disabled | constructor-only |
| form | constructor-only |
| highlightItemOnHover | constructor-only |
| modal | constructor-only |
| open | setter-backed |
| readOnly | constructor-only |
| value | setter-backed |
Runtime Setters
Form Participation
| Fact | Value |
|---|---|
| Form props | autoComplete, form, name, required, value |
| Hidden input | input (hidden) |
| Field integration | Yes |