The Select component is a wrapper around the native <select> element.
You can use the Select component, with the following props:
valueoptions[]children.statedefaultdefaulterrorsuccesswarningplaceholdersizemediumx-smallsmallmediumlargeblocktruedisabledfalseblocktrue<script lang="ts">
const roleOptions = [
{ value: 'admin', label: 'Administrator' },
{ value: 'editor', label: 'Editor' },
{ value: 'viewer', label: 'Viewer' },
{ value: 'billing', label: 'Billing Manager' }
];
let role = $state('admin');
</script>
<Select
bind:value={role}
options={roleOptions}
placeholder="Select a role"
/>Currently selected value:
<Select size="x-small" options={roleOptions} placeholder="Select a role" />
<Select size="small" options={roleOptions} placeholder="Select a role" />
<Select size="medium" options={roleOptions} placeholder="Select a role" />
<Select size="large" options={roleOptions} placeholder="Select a role" />The Select component supports custom snippets for adding icons or other elements
inside the select. Available snippets include: start and end.
<Select options={roleOptions} placeholder="Select a role">
{#snippet start()}
<IconSearch />
{/snippet}
</Select>Currently selected value:
For advanced use cases, you can pass custom children to the Select component instead
of using the options prop. This lets you use native <option> and <optgroup> elements directly, allowing for grouped
options, disabled options, or any other native select features.
<Select bind:value={region}>
{#snippet children()}
<option value="" disabled>Select a region</option>
<optgroup label="Americas">
<option value="us-east">US East</option>
<option value="us-west">US West</option>
<option value="ca-central">Canada Central</option>
</optgroup>
<optgroup label="Europe">
<option value="eu-west">EU West</option>
<option value="eu-central">EU Central</option>
</optgroup>
<optgroup label="Asia Pacific">
<option value="ap-southeast">AP Southeast</option>
<option value="ap-northeast">AP Northeast</option>
</optgroup>
{/snippet}
</Select>Currently selected value:
<Select
bind:value={value}
placeholder="Select a role"
options={roleOptions}
disabled
/>