Skip to main content

Starwind UI v3.0 is now available! Migration guide

Native Select

Info

For a styled select component, see the Select component.

Installation

Usage

---
import { NativeSelect, NativeSelectOption } from "@/components/starwind/native-select";
---
<NativeSelect class="w-[240px]">
<NativeSelectOption value="" disabled>Select a fruit</NativeSelectOption>
<NativeSelectOption value="apple">Apple</NativeSelectOption>
<NativeSelectOption value="banana">Banana</NativeSelectOption>
<NativeSelectOption value="blueberry">Blueberry</NativeSelectOption>
<NativeSelectOption value="pineapple">Pineapple</NativeSelectOption>
</NativeSelect>

Value

Astro marks the starting option with selected. React uses value and onChange. Vue uses v-model, and Svelte uses bind:value. In Vue, the model holds the selected option’s value. With the multiple attribute, it holds an array of values.

---
import { NativeSelect, NativeSelectOption } from "@/components/starwind/native-select";
---
<NativeSelect class="w-[240px]" name="fruit">
<NativeSelectOption value="apple">Apple</NativeSelectOption>
<NativeSelectOption value="banana" selected>Banana</NativeSelectOption>
<NativeSelectOption value="blueberry">Blueberry</NativeSelectOption>
</NativeSelect>

Composition

Place options directly inside NativeSelect, or organize them with NativeSelectOptGroup:

NativeSelect
├── NativeSelectOption
└── NativeSelectOptGroup
├── NativeSelectOption
└── NativeSelectOption

Groups

Use NativeSelectOptGroup to organize options into categories.

Disabled

Add the disabled prop to disable the entire select, or disable specific options.

Invalid

Use aria-invalid for assistive technology and data-error-visible to opt into the visible error state after validation has run.

Please select a framework.

Size

Use the size prop to render compact or larger controls.

Native Select vs Select

Use Native Select for simple forms when you want browser-native behavior and mobile pickers. Use Select when you need custom popover behavior, search, and advanced interaction patterns.

Tip

Prefer NativeSelect for straightforward form controls and mobile-first flows where native platform pickers are beneficial. Choose Select when you need richer UI features like searchable options, custom popover positioning, and advanced interactions.

RTL

Set dir="rtl" to support right-to-left languages.

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.

Native Select

Inherits select attributes. Omits `size`.

Contains the following additional props:

Prop Type Default Toggle details
size "sm" | "md" | "lg" "md"
Description
Selects the component's visual size.
Classification
Styled variant

Changelog

View version history v1.1.2 5 releases

v1.1.2

  • In Astro, an attribute that you set on NativeSelect and its parts now wins over the component’s own default for the same attribute, such as role or aria-label.
  • In Vue, v-model now works on NativeSelect. With the multiple attribute, the model holds an array of values.

v1.1.1

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

v1.1.0

  • The component is now available for React as well as Astro. Its props and styles stay the same.
  • Native Select now picks its option in the same way as an HTML select. If you set no value, the first option is selected. The old React-style defaultValue prop no longer has an effect.

v1.0.1

  • The Tailwind variants now live in their own variants.ts file in the component folder.

v1.0.0

  • Initial release with starwind v1.16.0