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.2.0 8 releases

v2.2.0

  • In Svelte, a defined value or open that you pass when Select mounts now stays under your control, as in React and Vue. To change it, use bind: or update your state in the change callback. A form reset keeps it. If you pass undefined at mount, Select keeps its own state.
  • Select.Value with its own content and no placeholder now shows that content until a value is chosen, in Astro and Vue. Before, the trigger was blank. React already did this.
  • In React, Select now shows the selected label when your own component renders the items. If your items load later, a value has no label until someone opens the list and picks an item.
  • In React, a Select now keeps the label of the parent value after the parent refuses a pick.
  • Pressing the trigger of an open Select in Safari now closes the list. Before, the list closed and opened again.
  • In Vue, SelectTrigger renders data-size, and Select.Trigger with asChild accepts a component child.
  • In Svelte, Select.Trigger still needs a button in child. With another element it does nothing, and it now logs a console error in production as well as in development.
  • In React, Select and Combobox inside a Field with a name now send their value when the form submits, and they call onValueChange, onOpenChange, and onInputValueChange. Before, the form often left the value out, and the callbacks did not run.
  • A name on a control now wins over the name on its Field, in all frameworks. If you set different names on a Field and its control, and your server reads the Field name, remove the name from the control.

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

  • Group headings are now linked to their groups with aria-labelledby, so screen readers announce the name of 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

  • The default export in index.ts now has a name, SelectParts, so framework tools show a clear name.

v2.0.1

  • SelectTrigger and SelectContent now each show their own size in data-size. The default is md. You do not need to change your props. To make the trigger and the popup the same size, set size on both.

v2.0.0

  • Select now gets its behavior from Starwind Runtime. Runtime handles selection, the form value, events, and scrolling. For a list that you can search, use Combobox.
  • See the Select Primitive for the unstyled parts and the behavior API.