View fulldotdev/ui on GitHub

Native Select

A styled native HTML select element with consistent design system integration.

Installation

npx shadcn@latest add @fulldev/native-select

Usage

import {
  NativeSelect,
  NativeSelectOptGroup,
  NativeSelectOption,
} from "@/components/ui/native-select"
<NativeSelect>
  <NativeSelectOption value="">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>

NativeSelect renders a real select inside a wrapper div. class goes to the wrapper; all other attributes, such as name, required, disabled and dir, go to the select, so it submits with a native form.

Composition

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

Groups

Use NativeSelectOptGroup to organize options into categories.

Disabled

Add the disabled prop to NativeSelect to disable the select.

Invalid

Use aria-invalid to show validation errors, and data-invalid on a surrounding Field for its styling.

Native Select vs Select

Use NativeSelect for native browser behavior, better performance, or mobile-optimized dropdowns. Use Select for custom styling of the open list.

RTL

Accessibility

  • It keeps all native select keyboard and screen reader behavior.
  • The chevron icon has aria-hidden="true".
  • Give the select a label, with Label for, aria-label or aria-labelledby.

API Reference

Source: src/components/ui/native-select

NativeSelect

PropTypeDefault
size"sm" | "default""default"
multiplebooleanfalse
disabledbooleanfalse

NativeSelectOption

PropTypeDefault
valuestring
disabledbooleanfalse

NativeSelectOptGroup

PropTypeDefault
labelstring
disabledbooleanfalse