Theme
Customize appearance
Components
Native Select
Use the browser’s built-in select control with consistent styling.
View component source ↗Preview
A minimal example to get started.
Installation
Install this component and its dependencies in a project initialized with shadcn.
pnpm dlx shadcn@latest add https://ui.hyunjoon.net/r/native-select.jsonUsage
This is the basic example. Use the Code tab above for the selected example. Adjust import aliases to match your project.
import { NativeSelect, NativeSelectOption } from "@/components/ui/native-select";
export default function Example() {
return (
<NativeSelect aria-label="Choose a region" defaultValue="asia">
<NativeSelectOption value="asia">Asia</NativeSelectOption>
<NativeSelectOption value="europe">Europe</NativeSelectOption>
<NativeSelectOption value="americas">Americas</NativeSelectOption>
</NativeSelect>
);
}
API reference
Derived from the installed component types. Native DOM props are also supported where applicable. A dash means no explicit default is documented. Some props depend on the selected mode.
NativeSelect
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | undefinedstring | undefined | — | Additional CSS classes merged with the component styles. |
defaultValue | string | number | readonly string[] | undefinedstring | number | readonly string[] | undefined | — | Initial value for an uncontrolled component. |
defaultChecked | boolean | undefinedboolean | undefined | — | Initial checked state for an uncontrolled control. |
ref | React.Ref<HTMLSelectElement> | undefinedReact.Ref<HTMLSelectElement> | undefined | — | Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). |
id | string | undefinedstring | undefined | — | Unique identifier used to associate labels and descriptions. |
children | React.ReactNodeReact.ReactNode | — | Content rendered inside this component. |
onFocus | React.FocusEventHandler<HTMLSelectElement> | undefinedReact.FocusEventHandler<HTMLSelectElement> | undefined | — | Called when the control receives focus. |
onBlur | React.FocusEventHandler<HTMLSelectElement> | undefinedReact.FocusEventHandler<HTMLSelectElement> | undefined | — | Called when the control loses focus. |
onChange | React.ChangeEventHandler<HTMLSelectElement, HTMLSelectElement> | undefinedReact.ChangeEventHandler<HTMLSelectElement, HTMLSelectElement> | undefined | — | Called when the underlying form control changes; inspect the event for its value. |
onKeyDown | React.KeyboardEventHandler<HTMLSelectElement> | undefinedReact.KeyboardEventHandler<HTMLSelectElement> | undefined | — | Called when a key is pressed while this element is focused. |
onClick | React.MouseEventHandler<HTMLSelectElement> | undefinedReact.MouseEventHandler<HTMLSelectElement> | undefined | — | Called when the element is activated. |
disabled | boolean | undefinedboolean | undefined | — | Prevents user interaction. |
name | string | undefinedstring | undefined | — | Field name used in form data. |
value | string | number | readonly string[] | undefinedstring | number | readonly string[] | undefined | — | The current value when controlled by the application. |
multiple | boolean | undefinedboolean | undefined | — | Allows more than one value to be selected. |
required | boolean | undefinedboolean | undefined | — | Whether the user must provide a value before form submission. |
size | "default" | "sm" | undefined"default" | "sm" | undefined | "default" | Visual size of the component. |
NativeSelectOptGroup
| Prop | Type | Default | Description |
|---|---|---|---|
ref | React.Ref<HTMLOptGroupElement> | undefinedReact.Ref<HTMLOptGroupElement> | undefined | — | Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). |
disabled | boolean | undefinedboolean | undefined | — | Prevents user interaction. |
defaultChecked | boolean | undefinedboolean | undefined | — | Initial checked state for an uncontrolled control. |
defaultValue | string | number | readonly string[] | undefinedstring | number | readonly string[] | undefined | — | Initial value for an uncontrolled component. |
className | string | undefinedstring | undefined | — | Additional CSS classes merged with the component styles. |
id | string | undefinedstring | undefined | — | Unique identifier used to associate labels and descriptions. |
children | React.ReactNodeReact.ReactNode | — | Content rendered inside this component. |
onFocus | React.FocusEventHandler<HTMLOptGroupElement> | undefinedReact.FocusEventHandler<HTMLOptGroupElement> | undefined | — | Called when the control receives focus. |
onBlur | React.FocusEventHandler<HTMLOptGroupElement> | undefinedReact.FocusEventHandler<HTMLOptGroupElement> | undefined | — | Called when the control loses focus. |
onChange | React.ChangeEventHandler<HTMLOptGroupElement, Element> | undefinedReact.ChangeEventHandler<HTMLOptGroupElement, Element> | undefined | — | Called when the underlying form control changes; inspect the event for its value. |
onKeyDown | React.KeyboardEventHandler<HTMLOptGroupElement> | undefinedReact.KeyboardEventHandler<HTMLOptGroupElement> | undefined | — | Called when a key is pressed while this element is focused. |
onClick | React.MouseEventHandler<HTMLOptGroupElement> | undefinedReact.MouseEventHandler<HTMLOptGroupElement> | undefined | — | Called when the element is activated. |
NativeSelectOption
| Prop | Type | Default | Description |
|---|---|---|---|
ref | React.Ref<HTMLOptionElement> | undefinedReact.Ref<HTMLOptionElement> | undefined | — | Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). |
disabled | boolean | undefinedboolean | undefined | — | Prevents user interaction. |
value | string | number | readonly string[] | undefinedstring | number | readonly string[] | undefined | — | The current value when controlled by the application. |
defaultChecked | boolean | undefinedboolean | undefined | — | Initial checked state for an uncontrolled control. |
defaultValue | string | number | readonly string[] | undefinedstring | number | readonly string[] | undefined | — | Initial value for an uncontrolled component. |
className | string | undefinedstring | undefined | — | Additional CSS classes merged with the component styles. |
id | string | undefinedstring | undefined | — | Unique identifier used to associate labels and descriptions. |
children | React.ReactNodeReact.ReactNode | — | Content rendered inside this component. |
onFocus | React.FocusEventHandler<HTMLOptionElement> | undefinedReact.FocusEventHandler<HTMLOptionElement> | undefined | — | Called when the control receives focus. |
onBlur | React.FocusEventHandler<HTMLOptionElement> | undefinedReact.FocusEventHandler<HTMLOptionElement> | undefined | — | Called when the control loses focus. |
onChange | React.ChangeEventHandler<HTMLOptionElement, Element> | undefinedReact.ChangeEventHandler<HTMLOptionElement, Element> | undefined | — | Called when the underlying form control changes; inspect the event for its value. |
onKeyDown | React.KeyboardEventHandler<HTMLOptionElement> | undefinedReact.KeyboardEventHandler<HTMLOptionElement> | undefined | — | Called when a key is pressed while this element is focused. |
onClick | React.MouseEventHandler<HTMLOptionElement> | undefinedReact.MouseEventHandler<HTMLOptionElement> | undefined | — | Called when the element is activated. |
Usage notes
Provide a label and a meaningful option value. Prefer it when native platform behavior is more important than a custom popup.