Native Select
A field that lets users choose one option from a list that the browser renders.
A native select lets users choose one option from a list. It styles the select element of the browser and leaves the open list to the browser, so the list appears in the form that users know from their browser and operating system. It accepts every attribute of the native select element except size: here, size sets the height of the select instead of the number of visible rows. A label names the choice, and htmlFor on the label refers to the id of the select, so a click on the label moves the focus to the select.
Usage
Examples
With Groups
A long list is easier to scan when its options follow categories that users already know, such as articles by department. Wrapped in a NativeSelectOptGroup, related options appear under the name given through label, and users can choose every option of the group but never its name.
Small
Above a table, a filter often shares a narrow row with other compact controls. With size set to "sm", the select takes less height, so it fits there and leaves the data in the foreground.
Default Size
Forms and dialogs need one consistent scale for all their fields. Unless another size is set, the select takes the size "default" and shares the height of an input, so a choice sits evenly among the entries around it.
Controlled
A choice often drives other parts of the screen, such as the figures that load for a selected week. Through value and onChange the application holds the selection, so it reacts to every change and can set the choice itself, for example when users reset their filters.
Disabled
Some choices apply only after an earlier step, such as a product line once users have chosen a brand. Until then, disabled keeps users from focusing the select or changing its choice, assistive technology reports it as unavailable, and the form leaves its value out on submit.
Invalid
A required choice can still be missing when users submit a form, such as the unit in which an article is ordered. Set on the select, aria-invalid marks the error for users and for assistive technology, so they find at once which choice needs a correction.
API Reference
NativeSelect
| Prop | size |
|---|---|
| Type | "sm" | "default" |
| Default | "default" |
| Description | Sets the height, the vertical padding and the corner radius of the select. It replaces the native size attribute, which sets the number of visible rows. |
NativeSelectOption
NativeSelectOption is one option that users can choose from the list. It renders an option and has no props of its own.
NativeSelectOptGroup
| Prop | label |
|---|---|
| Type | string |
| Default | – |
| Description | Names the group of options. The browser shows the name above the options of the group, and users can't choose it. |