NativeSelect
Data inputThe browser's own <select>, styled as a Zest field: <NativeSelect.Root> with bind:value, and its options given as items or as NativeSelect.Options (grouped in NativeSelect.OptGroups). placeholder adds an empty first option. Inside a Field it takes its id, label, description, error and invalid and disabled state from the Field.
import { NativeSelect } from '@limerdev/zest'; Select or Combobox. Several choices at once: use Checkboxes or a Combobox. Two or three options: use a RadioGroup.Examples
Basic
In a Field, with items and a placeholder. It posts with the form like any select.
Invoices are sent in it.
<script lang="ts">
import { Field, NativeSelect } from '@limerdev/zest';
let currency: string | undefined = $state();
</script>
<Field.Root class="w-full max-w-xs">
<Field.Label>Currency</Field.Label>
<NativeSelect.Root
name="currency"
placeholder="Choose a currency"
bind:value={currency}
items={[
{ value: 'SEK', label: 'Swedish krona' },
{ value: 'NOK', label: 'Norwegian krone' },
{ value: 'EUR', label: 'Euro' }
]}
/>
<Field.Description>Invoices are sent in it.</Field.Description>
</Field.Root> Groups
NativeSelect.Option and NativeSelect.OptGroup as children, for grouped options.
<script lang="ts">
import { Field, NativeSelect } from '@limerdev/zest';
</script>
<Field.Root class="w-full max-w-xs">
<Field.Label>Time zone</Field.Label>
<NativeSelect.Root name="timezone" value="Europe/Stockholm">
<NativeSelect.OptGroup label="Europe">
<NativeSelect.Option value="Europe/Stockholm">Stockholm</NativeSelect.Option>
<NativeSelect.Option value="Europe/Oslo">Oslo</NativeSelect.Option>
<NativeSelect.Option value="Europe/London">London</NativeSelect.Option>
</NativeSelect.OptGroup>
<NativeSelect.OptGroup label="America">
<NativeSelect.Option value="America/New_York">New York</NativeSelect.Option>
<NativeSelect.Option value="America/Los_Angeles">Los Angeles</NativeSelect.Option>
</NativeSelect.OptGroup>
</NativeSelect.Root>
</Field.Root> States
The Field's invalid and disabled states reach the select.
<script lang="ts">
import { Field, NativeSelect } from '@limerdev/zest';
const roles = [
{ value: 'member', label: 'Member' },
{ value: 'admin', label: 'Admin' }
];
</script>
<div class="flex w-full max-w-xs flex-col gap-6">
<Field.Root invalid>
<Field.Label>Role</Field.Label>
<NativeSelect.Root name="role" placeholder="Choose a role" items={roles} />
<Field.Error>Pick a role.</Field.Error>
</Field.Root>
<Field.Root disabled>
<Field.Label>Role (locked)</Field.Label>
<NativeSelect.Root name="locked-role" value="admin" items={roles} />
</Field.Root>
</div> Props
Every part also takes class (merged over its defaults), ref (bindable: the element), children, and child (a snippet that
renders your own element, with props to spread on it).
NativeSelect.Root
| Prop | Type | Default | Description |
|---|---|---|---|
| items | SelectOption[] | [] | The options, drawn when the select is given no children. |
| placeholder | string | undefined | A first option with an empty value, shown until the user picks: "Choose a country". It can't be picked again; with required, the form won't submit while it shows. |
| value bindable | string | – | The chosen option's value. Bindable. It starts on the placeholder, or on the first option when there is none. |
NativeSelect.Option
No props of its own beyond the common ones.
NativeSelect.OptGroup
No props of its own beyond the common ones.