NativeSelect
The browser's own select, styled like the other fields, which opens the system picker on a phone.
Native is a real <select> with the look of the package's fields and a chevron. The
browser draws the list, so on a phone the reader gets the system picker, and a form submits it as
it is. Use it for long lists on mobile, in plain forms, and where a custom popup would be out of
place; use Select when the options need more than text.
Value: NL
// apps/docs/examples/ui/native-select.tsx'use client';
import {useState} from 'react';
import { Field, FieldDescription, FieldLabel,} from '@workspace/active-ui/components/primitives/field';import { NativeSelect, NativeSelectOptGroup, NativeSelectOption,} from '@workspace/active-ui/components/primitives/native-select';
/** * The browser's own select, styled like the other fields: on a phone it * opens the system picker. Options can be grouped; the small size suits a * toolbar. It is a plain `<select>`, so a form submits it as is. */export default function NativeSelectExample() { const [country, setCountry] = useState('NL'); return ( <div className="grid w-full max-w-xs gap-6"> <Field> <FieldLabel htmlFor="native-country">Country of residence</FieldLabel> <NativeSelect id="native-country" name="country" className="w-full" value={country} onChange={(event) => setCountry(event.target.value)} > <NativeSelectOptGroup label="Benelux"> <NativeSelectOption value="BE">Belgium</NativeSelectOption> <NativeSelectOption value="LU">Luxembourg</NativeSelectOption> <NativeSelectOption value="NL">Netherlands</NativeSelectOption> </NativeSelectOptGroup> <NativeSelectOptGroup label="Other"> <NativeSelectOption value="DE">Germany</NativeSelectOption> <NativeSelectOption value="FR">France</NativeSelectOption> </NativeSelectOptGroup> </NativeSelect> <FieldDescription>Value: {country}</FieldDescription> </Field> <Field> <FieldLabel htmlFor="native-rows">Rows per page</FieldLabel> <NativeSelect id="native-rows" size="sm" defaultValue="25"> <NativeSelectOption value="10">10</NativeSelectOption> <NativeSelectOption value="25">25</NativeSelectOption> <NativeSelectOption value="50">50</NativeSelectOption> </NativeSelect> </Field> <Field data-disabled> <FieldLabel htmlFor="native-currency">Currency</FieldLabel> <NativeSelect id="native-currency" disabled defaultValue="EUR"> <NativeSelectOption value="EUR">Euro</NativeSelectOption> </NativeSelect> </Field> </div> );}Usage#
import { NativeSelect, NativeSelectOption,} from '@workspace/active-ui/components/primitives/native-select';
<NativeSelect id="rows" value={rows} onChange={(event) => setRows(event.target.value)}> <NativeSelectOption value="10">10</NativeSelectOption> <NativeSelectOption value="25">25</NativeSelectOption></NativeSelect>;Anatomy#
Native: theSelect <select>inside a wrapper that carries the chevron. Every attribute goes to the<select>;classgoes to the wrapper (soName w-widens both), andfull size(defaultorsm) sets the height. The HTMLsizeattribute (visible rows) is not available.NativeandSelect Option Native:Select Opt Group <option>and<optgroup>, in the system colours of the open list.
What your application provides#
A label: a
FieldwithLabel html.For The options, the value and
on, which receives the native change event.Change A width: the wrapper is as wide as its content (
w-); give itfit w-in a form.full
Accessibility and keyboard#
The browser's own control: Tab reaches it, the arrow keys change the value without opening it,
Alt+โ or Space opens the list, and typing jumps to an option. Disabled, it is skipped.
API#
NativeSelect
Props
- Type
"default""sm"- Default
'default'
The height of the field: default (36 px) or sm (32 px). It replaces the HTML size attribute (the number of visible rows).
Other props, such as the standard attributes of the underlying element, className and ref, are passed through.
Parts that take only their elementโs attributes
Native: the attributes of aSelect Opt Group <optgroup>, with className and ref.Native: the attributes of aSelect Option <option>, with className and ref.
This page adapts the Native Select documentation of shadcn/ui (MIT licence) to this package; see Third-party notices.