Native Select
Installation
npx @mielui/svelte add native-selectyarn dlx @mielui/svelte add native-selectbunx @mielui/svelte add native-selectUsage
Root renders a native <select>. Bind a string for single selection, or a string array when multiple is set. Option values are strings; group options with OptGroup and its label.
Name the select with a Label whose for matches its id, or with aria-label. Native form attributes and change events pass through, and size sets the number of visible rows. The browser handles validation, keyboard selection, and the mobile picker; use Select when you need a custom popup.
<script lang="ts">
import * as NativeSelect from '@mielui/svelte/components/native-select';
let timezone = $state('Europe/Paris');
</script>
<NativeSelect.Root name="timezone" bind:value={timezone} aria-label="Time zone">
<NativeSelect.Option value="Europe/Paris">Paris</NativeSelect.Option>
<NativeSelect.Option value="Europe/London">London</NativeSelect.Option>
</NativeSelect.Root>
Examples
Multiple selection
2 days selected. Use your platform's modifier keys to select several options.
Required field
API reference
NativeSelect.Root
multiplefalse | trueAllows several options to be selected and makes
valuean array.Default
falsevalueBindablestring | string[]Selected value, or an array when
multipleis set. Bindable.
NativeSelect.Option
valuestringValue submitted when this option is selected.
Other parts
These parts have no props of their own. They pass HTML attributes and events to their element.
NativeSelect.OptGroup
pnpm dlx @mielui/svelte add native-select