Skip to main content

Starwind UI v3.0 is now available! Migration guide

Installation

Usage

---
import { Select, SelectContent, SelectItem, SelectTrigger } from "@/components/starwind/select";
---
<Select name="framework">
<SelectTrigger placeholder="Choose a framework" />
<SelectContent>
<SelectItem value="astro">Astro</SelectItem>
<SelectItem value="react">React</SelectItem>
</SelectContent>
</Select>

Composition

Use this structure for a Select with grouped options:

Select
├── SelectTrigger
└── SelectContent
├── SelectGroup
│ ├── SelectLabel
│ └── SelectItem
├── SelectSeparator
└── SelectItem

Sizes

Set size on SelectTrigger and SelectContent separately. Both accept sm, md (the default), or lg. Set both to the same value for a consistent control, or use a larger content size when the popup needs more room.

Form Participation

Select serializes its value through a hidden input and follows native form reset behavior.

The browser checks a required Select when the form submits. This works in a plain <form> with no Starwind Form or Field. Press Continue with no plan chosen. The browser blocks the submit and shows its message at the Select, and focus moves to the Select button. The submit handler runs only after you choose a plan.

Programmatic Value Changes

Dispatch starwind:set-value on the Select root. Listen for the root-scoped starwind:value-change event when the selected value changes.

For a searchable text input with listbox suggestions, install Combobox instead of adding the removed search part.

API Reference

Styled Component API

These props are added or materially changed by the installed styled component. Standard HTML attributes remain available through the inherited interfaces noted below. Expand a prop to see named type definitions and framework-specific imports. Follow the Primitive and Runtime links for lower-level behavior props.

Select

Inherits div attributes. Omits `defaultValue` and `onChange`.

Contains the following additional props:

Prop Type Default Toggle details
defaultOpen boolean false
Description
Sets the initial open state when the component is uncontrolled.
Classification
Primitive override
Primitive prop
select.Root.defaultOpen
disabled boolean false
Description
Disables interaction with the component.
Classification
Primitive override
Primitive prop
select.Root.disabled
required boolean false
Description
Marks the control as required for form validation.
Classification
Primitive override
Primitive prop
select.Root.required

Select Trigger

Inherits button attributes.

Contains the following additional props:

Prop Type Default Toggle details
asChild boolean false
Description
Merges the component behavior and props into its child element.
Classification
Primitive override
Primitive prop
select.Trigger.asChild
iconClass string —
Description
Adds classes to the component's generated icon.
Classification
Wrapper prop
placeholder string —
Description
Provides fallback text for the value element generated inside the trigger.
Classification
Wrapper prop
showIcon boolean true
Description
Shows the component's generated icon.
Classification
Wrapper prop
size "sm" | "md" | "lg" "md"
Description
Selects the component's visual size.
Classification
Styled variant
valueClass string —
Description
Adds classes to the generated value element.
Classification
Wrapper prop

Select Value

Inherits span attributes.

Contains the following additional props:

Prop Type Default Toggle details
placeholder string —
Description
Provides fallback text when no value is available.
Classification
Wrapper prop

Select Content

Inherits div attributes.

Contains the following additional props:

Prop Type Default Toggle details
disablePortal boolean false
Description
Keeps the public Portal wrapper inline instead of moving it to a target.
Classification
Wrapper prop
portalContainer string —
Description
Sets the CSS selector for the public Portal wrapper target.
Classification
Wrapper prop
size "sm" | "md" | "lg" "md"
Description
Selects the component's visual size.
Classification
Wrapper prop

Select Item

Inherits div attributes. Omits `role`.

Contains the following additional props:

Prop Type Default Toggle details
disabled boolean false
Description
Disables interaction with the component.
Classification
Styled variant
Primitive prop
select.Item.disabled
indicatorClass string —
Description
Adds classes to the generated selection indicator.
Classification
Wrapper prop
inset boolean false
Description
Adds leading inset spacing for visual alignment.
Classification
Styled variant
showIndicator boolean true
Description
Shows the generated selection indicator.
Classification
Wrapper prop
value Required string —
Description
Controls or identifies the component value.
Classification
Primitive override
Primitive prop
select.Item.value

Primitive And Runtime API

Use these references when you need the lower-level behavior APIs behind Select.

Primitive API

Runtime API

Select primitive
createSelect from @starwind-ui/runtime/select

Changelog

View version history v2.1.3 7 releases

v2.1.3

  • A required Select now stops a plain HTML form from submitting when no option is selected. The browser shows its message next to the Select and puts focus on the Select button. Before, the empty form submitted.
  • A Select without required still lets the Enter key submit the form as before.
  • When a required Select is the first field with an error in a Starwind Form, submit and validate({ focus: true }) now put focus on the Select button, and the page scrolls to it.

v2.1.2

  • Select labels in Vue and Svelte now update when the selected option’s text changes or its option loads after the value is set, whether the popup is open or closed.
  • Vue Select keeps its previous selection and open state when a change is canceled.
  • Reduced background work when a React page uses multiple menus, tooltips, or other portals.
  • Vue Select Trigger now accepts asChild so you can use your own element as the trigger.
  • React Select keeps its current selection when a reset is canceled and preserves newer values while a reset is pending. Keep it in the same form until that reset finishes.
  • Fixed nested Svelte overlays inside a dialog appearing behind their parent or failing to receive clicks.
  • Fixed nested overlays appearing behind their parent in Vue and Svelte. Overlays can now render under the document body; if custom CSS or DOM queries require them to stay inside a parent, set a portal container or add data-floating-root to that parent.
  • Reduced the JavaScript loaded by Select when it is used without Field.
  • Fixed React 18 retaining removed popup elements when the parent component stays mounted.

v2.1.1

  • Connected group headings to their groups with aria-labelledby so assistive technology can identify each group.

v2.1.0

  • Added portalContainer and disablePortal to SelectContent for custom portal targets and inline rendering.
  • Corrected touch interaction so tapping an open trigger closes the popup and tapping an item selects its value on mobile browsers.

v2.0.2

  • Named the generated aggregate default export so React and Astro tooling can identify the installed component cleanly.

v2.0.1

  • SelectTrigger and SelectContent now expose their independently resolved size as data-size, including the md default. No prop migration is required; set both props when the control and portal should match.

v2.0.0

  • Rebuilt Select on Starwind Runtime for selection, forms, events, and scroll behavior; search is now provided by Combobox.
  • See the Select Primitive for the underlying unstyled anatomy and behavior API.