Skip to main content

Starwind UI v1.12 is now available!

Select

Installation

Usage

size

You can control the size of the select trigger and content using the size prop. Available sizes are "sm", "md" (default), and "lg".

side, align, and sideOffset

You can control the position of the select dropdown using the side, align and sideOffset props on SelectContent.

disabled

You can disable the select trigger or individual items.

Form Handling

This component mirrors the behavior of a standard HTML select element. Internally, it renders a hidden <select> to integrate seamlessly with forms.

Tip

Open up the dev tools console to see the form data on submission.

Create project
Deploy your new project in one-click.

With Search (Combobox)

New Add a search input to filter through select options, creating a combobox pattern. The SelectSearch component provides built-in filtering functionality.

With Groups and Labels

Group related items together and add labels for better organization.

Programmatic Control

You can programmatically select an option by dispatching a custom SelectEvent with the value property set to the desired option’s value. You also need to pass either the name or id of the select element to the event.

Change Event Handling

The select component emits a starwind-select:change event when a selection is made. The selected value can be accessed through event.detail.value.

<Select>
<SelectTrigger class="w-[180px]">
<SelectValue placeholder="Select option" />
</SelectTrigger>
<SelectContent>
<SelectItem value="1">Option 1</SelectItem>
<SelectItem value="2">Option 2</SelectItem>
</SelectContent>
</Select>
<script>
document.querySelector('.starwind-select')?.addEventListener('starwind-select:change', (event) => {
console.log('Selected value:', event.detail.value);
});
</script>

API Reference

Select

The root component that manages the select state.

PropTypeDefault
idstring-
namestring-
defaultValuestring-
classstring-
<Select name="framework">
<!-- Select components -->
</Select>

Additional Notes:

  • name: Name attribute for form handling

SelectTrigger

The button that toggles the select dropdown.

PropTypeDefault
size"sm" | "md" | "lg""md"
requiredbooleanfalse
disabledbooleanfalse
classstring-
<SelectTrigger class="w-[180px]">
<SelectValue placeholder="Select" />
</SelectTrigger>

SelectContent

The dropdown content that appears when the select is open.

PropTypeDefault
size"sm" | "md" | "lg""md"
side"top" | "bottom""bottom"
align"start" | "center" | "end""start"
sideOffsetnumber4
animationDurationnumber150
classstring-
<SelectContent>
<!-- Select items -->
</SelectContent>

Additional Notes:

  • side: Side of the dropdown relative to the trigger
  • align: Alignment of the dropdown relative to the trigger
  • sideOffset: Offset distance in pixels from the trigger
  • animationDuration: Open and close animation duration in milliseconds

SelectItem

An item that can be selected. Requires a value prop.

PropTypeDefault
valuestringRequired
disabledbooleanfalse
classstring-
<SelectItem value="astro">Astro</SelectItem>

SelectValue

The component that displays the selected value or placeholder text in the trigger.

PropTypeDefault
placeholderstring"select"
classstring-
<SelectValue placeholder="Select a framework" />

SelectGroup

A component used to group related select items together.

PropTypeDefault
classstring-
<SelectGroup>
<SelectLabel>Frameworks</SelectLabel>
<!-- Select items -->
</SelectGroup>

SelectLabel

A label component used to give a title to a group of items.

PropTypeDefault
classstring-
<SelectLabel>Frameworks</SelectLabel>

SelectSeparator

A visual separator that can be used between select items.

PropTypeDefault
classstring-
<SelectSeparator />

SelectSearch

A search input component that filters select items in real-time, creating a combobox pattern.

PropTypeDefault
placeholderstring"Search..."
emptyTextstring"No results found."
classstring-
<SelectSearch placeholder="Search frameworks..." />

Additional Notes:

  • Place inside SelectContent before the items you want to filter
  • emptyText: Text to display when no items match the search

Changelog

v1.8.0

  • Add required prop to Select to enable form validation

v1.7.0

  • Add SelectSearch component to enable combobox capability
  • Add size prop to SelectTrigger and SelectContent
  • Styling improvements

v1.6.1

  • Add named slot “icon” to SelectItem and SelectTrigger to enable easy icon swapping

v1.6.0

  • style and focus state updates

v1.5.0

  • Add data-slot attribute to enable global styling updates

v1.4.1

  • Add type exports for SelectEvent and SelectChangeEvent.

v1.4.0

  • Add the ability to programmatically select an item through a new event listener for a custom SelectEvent.

v1.3.2

  • No longer return focus if clicking outside of the select menu. Focus will now only return to the select trigger on item selection, or when closing with the keyboard.

v1.3.1

  • Fix exit animation

v1.3.0

  • Add support for a defaultValue prop to enable initial selection of an option
  • Add support for align prop on SelectContent
  • Update open and close animations to match DropdownContent

v1.2.0

  • Allow a “name” attribute to enable simple form handling by leveraging the hidden html <select> element that is auto-generated.
  • Add empty aria-controls="" to SelectTrigger to make eslint happy. It is still assigned by the script.

v1.1.0

  • tailwind-variants now implemented. This uses tailwind-merge under the hood to merge Tailwind classes without style conflicts, allowing you to override any existing classes using the “class” prop.