oakoss/ui
Components

Native Select

The browser's own select, styled to match the other fields, with a label, description and validation message.

Source
We ship to these countries.

Installation

npx shadcn@latest add @oakoss/native-select

Usage

import {
  NativeSelect,
  NativeSelectOption,
} from '#/components/ui/inputs/native-select';

<NativeSelect label="Fruit" name="fruit">
  <NativeSelectOption value="apple">Apple</NativeSelectOption>
  <NativeSelectOption value="pear">Pear</NativeSelectOption>
</NativeSelect>;

The children are the options, NativeSelectOption and NativeSelectOptGroup. label, description, errors, errorMessage and size (sm, md, lg, matching Input's heights) set up the field around the select, as on Text Field. Every other prop goes to the <select>, so name, required, disabled, value, onChange and ref work as they do on the element, and a form library's field props spread onto it.

Native Select or Select

Native Select is the browser's own control: phones open their system picker, it works before JavaScript loads, and it handles long plain lists well. Its options are text only, and the open list looks like the browser's, not the theme's. Select draws its own list, so options can carry descriptions, sections and icons, and it looks the same everywhere; it still renders a hidden native select for autofill and form submission.

Examples

Validation

The field doesn't validate on its own. Pass isInvalid with errors or errorMessage, from your form library or your own checks; required still gets the browser's message when the form is submitted. Inside React Aria's Form, validationErrors reach the select by its name, as they do the other fields.

Choose a size.

Multiple selection

multiple shows the options as a list box, with no chevron.

Hold Ctrl or ⌘ to pick several.

Accessibility

The select is a native control, so browsers and screen readers handle it fully, and React Aria adds no keys: the browser's own apply. The label names it, and the description and error describe it. isInvalid sets aria-invalid and turns the border destructive, and required marks the label with an asterisk. In Windows High Contrast a disabled select keeps the system's disabled color without fading further.

API

NativeSelect

Extends the HTML select element.

Props

Prop

Type

Also accepts all native <select> attributes; size is ours, not the attribute's row count.

Data attributes

AttributePresent when
data-slotnative-select (select)
data-sizeAlways, on the select
data-invalidisInvalid is set
data-disableddisabled is set (field)

Other parts

PartExtendsdata-slot
NativeSelectOptionHTML optionnative-select-option
NativeSelectOptGroupHTML optgroupnative-select-optgroup