Combobox Primitive
Combobox is a Starwind Runtime primitive in the floating-value-control contract family.
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
defaultOpen boolean -
- Description
- Sets whether Combobox starts open.
- Kind
- control
- Targets
- -
- Full type
- boolean
value string | null -
- Description
- Controls the current Combobox value.
- Kind
- control
- Targets
- -
- Full type
- string | null
defaultValue string | null -
- Description
- Sets the initial Combobox value for uncontrolled usage.
- Kind
- control
- Targets
- -
- Full type
- string | null
inputValue string -
- Description
- Controls the input value for Combobox.
- Kind
- control
- Targets
- -
- Full type
- string
defaultInputValue string -
- Description
- Controls the default input value for Combobox.
- Kind
- control
- Targets
- -
- Full type
- string
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
onOpenChange (open: boolean, details: ComboboxOpenChangeDetails) => void -
- Description
- Runs when Combobox opens or closes.
- Kind
- callback
- Targets
- -
- Full type
- (open: boolean, details: ComboboxOpenChangeDetails) => void
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
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
- -
- Cancelable
- Yes
openChange onOpenChange open: boolean
- Description
- Fires when Combobox opens or closes.
- DOM event
- starwind:open-change
- Details type
- ComboboxOpenChangeDetails
- Timing
- -
- Cancelable
- Yes
valueChange onValueChange value: string | null
- Description
- Fires when the value changes for Combobox.
- DOM event
- starwind:value-change
- Details type
- ComboboxValueChangeDetails
- Timing
- -
- Cancelable
- Yes
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
- State control support
- React supports controlled and default state with inputValue and defaultInputValue props. Runtime/HTML reads initial state from data-default-input-value, emits starwind:input-value-change, and updates with setInputValue. Astro adapters render initial/default state, but do not expose reactive controlled-state props for this state.
open boolean open / defaultOpen
- Description
- Tracks whether Combobox 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 Combobox 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 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 |