Combobox Primitive
Combobox is a Starwind Runtime primitive in the floating-value-control 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 Combobox anatomy with the Runtime wiring included.
---import { Combobox } from "@starwind-ui/astro/combobox";---
<Combobox.Root> <Combobox.Label>Choose a framework</Combobox.Label> <Combobox.InputGroup> <Combobox.Input placeholder="Search frameworks" /> <Combobox.Trigger>Open</Combobox.Trigger> <Combobox.Clear>Clear</Combobox.Clear> </Combobox.InputGroup> <Combobox.Positioner> <Combobox.Popup> <Combobox.Empty>No results</Combobox.Empty> </Combobox.Popup> </Combobox.Positioner></Combobox.Root>Use the React primitive adapter when Combobox state participates in React rendering.
import { Combobox } from "@starwind-ui/react/combobox";
export function Example() { return ( <Combobox.Root> <Combobox.Label>Choose a framework</Combobox.Label> <Combobox.InputGroup> <Combobox.Input placeholder="Search frameworks" /> <Combobox.Trigger>Open</Combobox.Trigger> <Combobox.Clear>Clear</Combobox.Clear> </Combobox.InputGroup> <Combobox.Positioner> <Combobox.Popup> <Combobox.Empty>No results</Combobox.Empty> </Combobox.Popup> </Combobox.Positioner> </Combobox.Root> );}Render the Combobox data-sw-* contract yourself, then initialize createCombobox.
<div data-sw-combobox> <div data-sw-combobox-label>Choose a framework</div> <div data-sw-combobox-input-group> <input data-sw-combobox-input role="combobox" aria-autocomplete="list" autocomplete="off" placeholder="Search frameworks" /> <button data-sw-combobox-trigger aria-haspopup="listbox">Open</button> <button data-sw-combobox-clear type="button">Clear</button> </div> <div data-sw-combobox-positioner> <div data-sw-combobox-popup role="listbox" hidden tabindex="-1"> <div data-sw-combobox-empty hidden>No results</div> <div data-sw-combobox-list> <div data-sw-combobox-item role="option" data-value="astro"> <span data-sw-combobox-item-text>Astro</span> <span data-sw-combobox-item-indicator aria-hidden="true" hidden></span> </div> </div> </div> </div></div>
<script type="module"> import { createCombobox } from "@starwind-ui/runtime/combobox";
const root = document.querySelector("[data-sw-combobox]"); if (root) { createCombobox(root); }</script>Floating Behavior
| Fact | Value |
|---|---|
| Anchor part | inputGroup |
| Positioner part | positioner |
| Popup part | popup |
| Portal part | portal |
| Option props | side, align, sideOffset, alignOffset, avoidCollisions |
API Reference
Root
The main element that owns the Combobox Runtime instance.
- Default element
- div
- Discovery hook
- data-sw-combobox
- Role
- -
Props
open boolean -
- Description
- Controls whether Combobox is open.
- Kind
- control
- Targets
- -
- Full type
- boolean
- React
Use open for controlled state and defaultOpen for default state, and onOpenChange for change proposals.
opendefaultOpenonOpenChange
- Astro
Use open or defaultOpen for initial state, listen for starwind:open-change, and call setOpen for later updates.
opendefaultOpenstarwind:open-changesetOpen
- Runtime / HTML
Use data-default-open for initial state, listen for starwind:open-change, and call setOpen for later updates.
data-default-openstarwind:open-changesetOpen
defaultOpen boolean -
- Description
- Sets whether Combobox starts open.
- Kind
- control
- Targets
- -
- Full type
- boolean
- React
Use open for controlled state and defaultOpen for default state, and onOpenChange for change proposals.
opendefaultOpenonOpenChange
- Astro
Use open or defaultOpen for initial state, listen for starwind:open-change, and call setOpen for later updates.
opendefaultOpenstarwind:open-changesetOpen
- Runtime / HTML
Use data-default-open for initial state, listen for starwind:open-change, and call setOpen for later updates.
data-default-openstarwind:open-changesetOpen
value string | null -
- Description
- Controls the current Combobox value.
- Kind
- control
- Targets
- -
- Full type
- string | null
- 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 string | null -
- Description
- Sets the initial Combobox value for uncontrolled usage.
- Kind
- control
- Targets
- -
- Full type
- string | null
- 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
inputValue string -
- Description
- Controls the input value for Combobox.
- Kind
- control
- Targets
- -
- Full type
- string
- React
Use inputValue for controlled state and defaultInputValue for default state, and onInputValueChange for change proposals.
inputValuedefaultInputValueonInputValueChange
- Astro
Use inputValue or defaultInputValue for initial state, listen for starwind:input-value-change, and call setInputValue for later updates.
inputValuedefaultInputValuestarwind:input-value-changesetInputValue
- Runtime / HTML
Use data-default-input-value for initial state, listen for starwind:input-value-change, and call setInputValue for later updates.
data-default-input-valuestarwind:input-value-changesetInputValue
defaultInputValue string -
- Description
- Controls the default input value for Combobox.
- Kind
- control
- Targets
- -
- Full type
- string
- React
Use inputValue for controlled state and defaultInputValue for default state, and onInputValueChange for change proposals.
inputValuedefaultInputValueonInputValueChange
- Astro
Use inputValue or defaultInputValue for initial state, listen for starwind:input-value-change, and call setInputValue for later updates.
inputValuedefaultInputValuestarwind:input-value-changesetInputValue
- Runtime / HTML
Use data-default-input-value for initial state, listen for starwind:input-value-change, and call setInputValue for later updates.
data-default-input-valuestarwind:input-value-changesetInputValue
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
filterMode "contains" | "startsWith" "contains"
- Description
- Configures the filter mode option for the Root part.
- Kind
- option
- Targets
- -
- Full type
- "contains" | "startsWith"
form string -
- Description
- Associates the control with a form element.
- Kind
- option
- Targets
- -
- Full type
- string
highlightItemOnHover boolean true
- Description
- Highlights Combobox items when the pointer moves over them.
- Kind
- option
- Targets
- -
- Full type
- boolean
locale string -
- Description
- Sets the locale used by Combobox.
- Kind
- option
- Targets
- -
- Full type
- string
modal boolean false
- Description
- Makes Combobox behave as a modal overlay.
- Kind
- option
- Targets
- -
- 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
onInputValueChange (inputValue: string, details: ComboboxInputValueChangeDetails) => void -
- Description
- Runs when on input value change changes for Combobox.
- Kind
- callback
- Targets
- -
- Full type
- (inputValue: string, details: ComboboxInputValueChangeDetails) => void
- React
Use inputValue for controlled state and defaultInputValue for default state, and onInputValueChange for change proposals.
inputValuedefaultInputValueonInputValueChange
- Astro
Use inputValue or defaultInputValue for initial state, listen for starwind:input-value-change, and call setInputValue for later updates.
inputValuedefaultInputValuestarwind:input-value-changesetInputValue
- Runtime / HTML
Use data-default-input-value for initial state, listen for starwind:input-value-change, and call setInputValue for later updates.
data-default-input-valuestarwind:input-value-changesetInputValue
onOpenChange (open: boolean, details: ComboboxOpenChangeDetails) => void -
- Description
- Runs when Combobox opens or closes.
- Kind
- callback
- Targets
- -
- Full type
- (open: boolean, details: ComboboxOpenChangeDetails) => void
- React
Use open for controlled state and defaultOpen for default state, and onOpenChange for change proposals.
opendefaultOpenonOpenChange
- Astro
Use open or defaultOpen for initial state, listen for starwind:open-change, and call setOpen for later updates.
opendefaultOpenstarwind:open-changesetOpen
- Runtime / HTML
Use data-default-open for initial state, listen for starwind:open-change, and call setOpen for later updates.
data-default-openstarwind:open-changesetOpen
onValueChange (value: string | null, details: ComboboxValueChangeDetails) => void -
- Description
- Runs when the Combobox value changes.
- Kind
- callback
- Targets
- -
- Full type
- (value: string | null, details: ComboboxValueChangeDetails) => 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
inputValueChange onInputValueChange inputValue: string
- Description
- Fires when the text input value changes for Combobox.
- DOM event
- starwind:input-value-change
- Details type
- ComboboxInputValueChangeDetails
- 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.
openChange onOpenChange open: boolean
- Description
- Fires when Combobox opens or closes.
- DOM event
- starwind:open-change
- Details type
- ComboboxOpenChangeDetails
- 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.
valueChange onValueChange value: string | null
- Description
- Fires when the value changes for Combobox.
- DOM event
- starwind:value-change
- Details type
- ComboboxValueChangeDetails
- 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
inputValue string inputValue / defaultInputValue
- Description
- Tracks the current text input value for Combobox.
- Initial attribute
- data-default-input-value
- Runtime getter
- getInputValue
- Runtime setter
- setInputValue
- React
Use inputValue for controlled state and defaultInputValue for default state, and onInputValueChange for change proposals.
inputValuedefaultInputValueonInputValueChange
- Astro
Use inputValue or defaultInputValue for initial state, listen for starwind:input-value-change, and call setInputValue for later updates.
inputValuedefaultInputValuestarwind:input-value-changesetInputValue
- Runtime / HTML
Use data-default-input-value for initial state, listen for starwind:input-value-change, and call setInputValue for later updates.
data-default-input-valuestarwind:input-value-changesetInputValue
open boolean open / defaultOpen
- Description
- Tracks whether Combobox is open.
- Initial attribute
- data-default-open
- Runtime getter
- getOpen
- Runtime setter
- setOpen
- React
Use open for controlled state and defaultOpen for default state, and onOpenChange for change proposals.
opendefaultOpenonOpenChange
- Astro
Use open or defaultOpen for initial state, listen for starwind:open-change, and call setOpen for later updates.
opendefaultOpenstarwind:open-changesetOpen
- Runtime / HTML
Use data-default-open for initial state, listen for starwind:open-change, and call setOpen for later updates.
data-default-openstarwind:open-changesetOpen
value string | null value / defaultValue
- Description
- Tracks the current Combobox 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
Label
Text label associated with Combobox.
- Default element
- div
- Discovery hook
- data-sw-combobox-label
- Role
- -
Data Attributes
Runtime hooks
Input Group
Groups the input controls for Combobox.
- Default element
- div
- Discovery hook
- data-sw-combobox-input-group
- Role
- -
Data Attributes
Runtime hooks
Input
The native input synchronized by Combobox.
- Default element
- input
- Discovery hook
- data-sw-combobox-input
- Role
- combobox
Data Attributes
Runtime hooks
Trigger
The control that opens, closes, or targets the Combobox content.
- Default element
- button
- Discovery hook
- data-sw-combobox-trigger
- Role
- -
Props
asChild boolean -
- Description
- Merges behavior onto your child element instead of rendering the default Trigger element.
- Kind
- rendering
- Targets
- clear, trigger
- Full type
- boolean
Data Attributes
Runtime hooks
State
Icon
Decorative icon rendered by Combobox.
- Default element
- span
- Discovery hook
- data-sw-combobox-icon
- Role
- -
Data Attributes
Runtime hooks
Clear
Clears the current Combobox value.
- Default element
- button
- Discovery hook
- data-sw-combobox-clear
- Role
- -
Props
asChild boolean -
- Description
- Merges behavior onto your child element instead of rendering the default Clear element.
- Kind
- rendering
- Targets
- clear, trigger
- Full type
- boolean
Data Attributes
Runtime hooks
Value
Displays the current Combobox value.
- Default element
- span
- Discovery hook
- data-sw-combobox-value
- Role
- -
Data Attributes
Runtime hooks
Hidden Input
The hidden native input synchronized by Combobox.
- Default element
- input
- Discovery hook
- data-sw-combobox-hidden-input
- Role
- -
Data Attributes
Runtime hooks
Portal
Moves Combobox overlay content to the document body when needed.
- Default element
- div
- Discovery hook
- data-sw-combobox-portal
- Role
- -
Data Attributes
Runtime hooks
Positioner
Positions the Combobox content relative to its trigger.
- Default element
- div
- Discovery hook
- data-sw-combobox-positioner
- Role
- -
Props
side "top" | "right" | "bottom" | "left" "bottom"
- Description
- Sets the preferred side for Combobox content.
- Kind
- option
- Targets
- positioner, popup
- Full type
- "top" | "right" | "bottom" | "left"
align "start" | "center" | "end" "start"
- Description
- Sets how Combobox content aligns to its trigger.
- Kind
- option
- Targets
- positioner, popup
- Full type
- "start" | "center" | "end"
sideOffset number 4
- Description
- Sets the distance between Combobox content and its trigger.
- Kind
- option
- Targets
- positioner, popup
- Full type
- number
alignOffset number 0
- Description
- Adjusts the cross-axis alignment offset for Combobox content.
- Kind
- option
- Targets
- positioner, popup
- Full type
- number
avoidCollisions boolean true
- Description
- Allows Combobox content to shift or flip to stay visible.
- Kind
- option
- Targets
- positioner, popup
- Full type
- boolean
Data Attributes
Runtime hooks
Metadata
Popup
The floating content container for Combobox.
- Default element
- div
- Discovery hook
- data-sw-combobox-popup
- Role
- listbox
Props
side "top" | "right" | "bottom" | "left" "bottom"
- Description
- Sets the preferred side for Combobox content.
- Kind
- option
- Targets
- positioner, popup
- Full type
- "top" | "right" | "bottom" | "left"
align "start" | "center" | "end" "start"
- Description
- Sets how Combobox content aligns to its trigger.
- Kind
- option
- Targets
- positioner, popup
- Full type
- "start" | "center" | "end"
sideOffset number 4
- Description
- Sets the distance between Combobox content and its trigger.
- Kind
- option
- Targets
- positioner, popup
- Full type
- number
alignOffset number 0
- Description
- Adjusts the cross-axis alignment offset for Combobox content.
- Kind
- option
- Targets
- positioner, popup
- Full type
- number
avoidCollisions boolean true
- Description
- Allows Combobox content to shift or flip to stay visible.
- Kind
- option
- Targets
- positioner, popup
- Full type
- boolean
Data Attributes
Runtime hooks
State
Metadata
Empty
Content shown when Combobox has no matching items.
- Default element
- div
- Discovery hook
- data-sw-combobox-empty
- Role
- -
Data Attributes
Runtime hooks
List
The list of selectable Combobox items.
- Default element
- div
- Discovery hook
- data-sw-combobox-list
- Role
- -
Data Attributes
Runtime hooks
Group
Groups related Combobox items.
- Default element
- div
- Discovery hook
- data-sw-combobox-group
- Role
- group
Data Attributes
Runtime hooks
Group Label
Labels a group of Combobox items.
- Default element
- div
- Discovery hook
- data-sw-combobox-group-label
- Role
- -
Data Attributes
Runtime hooks
Item
An interactive item inside the Combobox collection.
- Default element
- div
- Discovery hook
- data-sw-combobox-item
- Role
- option
Data Attributes
Runtime hooks
Metadata
Item Text
Text content for a Combobox item.
- Default element
- span
- Discovery hook
- data-sw-combobox-item-text
- Role
- -
Data Attributes
Runtime hooks
Item Indicator
Shows the selected state for a Combobox item.
- Default element
- span
- Discovery hook
- data-sw-combobox-item-indicator
- Role
- -
Data Attributes
Runtime hooks
State
Separator
Separates groups of Combobox items.
- Default element
- div
- Discovery hook
- data-sw-combobox-separator
- Role
- separator
Data Attributes
Runtime hooks
Runtime API
- Factory
createCombobox- Import
@starwind-ui/runtime/combobox- Root hook
- root
data-sw-combobox - Option props
- autoComplete, defaultInputValue, defaultOpen, defaultValue, disabled, filterMode, form, highlightItemOnHover, inputValue, locale, modal, name, open, readOnly, required, value
Option Lifecycles
| Option | Lifecycle |
|---|---|
| autoComplete | setter-backed |
| defaultInputValue | constructor-only |
| defaultOpen | constructor-only |
| defaultValue | constructor-only |
| disabled | setter-backed |
| filterMode | constructor-only |
| form | setter-backed |
| highlightItemOnHover | constructor-only |
| inputValue | setter-backed |
| locale | constructor-only |
| modal | constructor-only |
| name | setter-backed |
| open | setter-backed |
| readOnly | constructor-only |
| required | setter-backed |
| value | setter-backed |
Runtime Setters
Form Participation
| Fact | Value |
|---|---|
| Form props | autoComplete, form, name, required, value |
| Hidden input | hiddenInput (hidden) |
| Field integration | Yes |
Related Styled Components
Changelog
View version history v1.0.0 4 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.2
- Marked generated React Primitive files as client modules so vendored installs preserve client boundaries in React server frameworks.
- Kept generated React state-change callbacks and DOM events cancelable until the Runtime accepts the proposed state, then synchronized rendered state.
- Preserved cancellation for React Combobox value and input commands.
v0.1.1
- Added modal background-scroll locking while the combobox popup is open.
v0.1.0
- Introduced filtering, selection, keyboard navigation, floating-list placement, and form participation.