Select
A dropdown select with icons, avatars, grouped items, descriptions, and custom rendering. Built on bits-ui with full keyboard navigation.
name now submits the selection with the
form, one entry per value with multiple, and required and form.reset() work as they do on a native select.
Items can use an empty string as their value. The trigger button no longer carries name, so a selector like button[name="country"] no longer matches: target the
trigger with its id or [data-select-trigger].Playground
Experiment with different props in real-time.
Basic Usage
Pass items and use bind:value.
<script lang="ts">
import { Select } from 'sv5ui';
let value = $state('');
const countries = [
{ value: 'us', label: 'United States' },
{ value: 'ca', label: 'Canada' },
{ value: 'mx', label: 'Mexico' },
{ value: 'br', label: 'Brazil' },
{ value: 'ar', label: 'Argentina' }
];
</script>
<Select items={countries} bind:value placeholder="Select a country" />Variants
5 trigger visual styles.
<Select items={frameworks} variant="outline" placeholder="Outline" />
<Select items={frameworks} variant="none" placeholder="None" />
<Select items={frameworks} variant="soft" placeholder="Soft" />
<Select items={frameworks} variant="subtle" placeholder="Subtle" />
<Select items={frameworks} variant="ghost" placeholder="Ghost" />Sizes
5 sizes.
<Select items={frameworks} size="xs" placeholder="Extra Small" />
<Select items={frameworks} size="sm" placeholder="Small" />
<Select items={frameworks} size="md" placeholder="Medium" />
<Select items={frameworks} size="lg" placeholder="Large" />
<Select items={frameworks} size="xl" placeholder="Extra Large" />Colors
Color schemes visible with highlight.
<Select items={frameworks} color="primary" placeholder="Primary" />
<Select items={frameworks} color="secondary" placeholder="Secondary" />
<Select items={frameworks} color="success" placeholder="Success" />
<Select items={frameworks} color="warning" placeholder="Warning" />
<Select items={frameworks} color="error" placeholder="Error" />
<Select items={frameworks} color="info" placeholder="Info" />With Icons
Add icons to items and the trigger.
<script lang="ts">
const browsers = [
{ value: 'chrome', label: 'Chrome', icon: 'logos:chrome' },
{ value: 'firefox', label: 'Firefox', icon: 'logos:firefox' },
{ value: 'safari', label: 'Safari', icon: 'logos:safari' },
{ value: 'edge', label: 'Edge', icon: 'logos:microsoft-edge' }
];
</script>
<Select items={browsers} placeholder="Choose a browser" icon="lucide:globe" />With Descriptions
Add secondary text to items.
<script lang="ts">
const roles = [
{ value: 'admin', label: 'Admin', description: 'Full access to all resources' },
{ value: 'editor', label: 'Editor', description: 'Can edit and publish content' },
{ value: 'viewer', label: 'Viewer', description: 'Read-only access' }
];
</script>
<Select items={roles} placeholder="Assign a role" />Grouped Items
Use type: 'label' and type: 'separator'.
<script lang="ts">
const items = [
{ type: 'label', label: 'Frontend' },
{ value: 'react', label: 'React' },
{ value: 'vue', label: 'Vue' },
{ value: 'svelte', label: 'Svelte' },
{ type: 'separator' },
{ type: 'label', label: 'Backend' },
{ value: 'node', label: 'Node.js' },
{ value: 'python', label: 'Python' },
{ value: 'go', label: 'Go' }
];
</script>
<Select items={items} placeholder="Pick a technology" />With Avatar
Display avatars alongside items.
<script lang="ts">
const members = [
{ value: 'alice', label: 'Alice Martin', avatar: { src: 'https://i.pravatar.cc/40?u=alice', alt: 'Alice' } },
{ value: 'bob', label: 'Bob Wilson', avatar: { src: 'https://i.pravatar.cc/40?u=bob', alt: 'Bob' } },
{ value: 'carol', label: 'Carol Lee', avatar: { src: 'https://i.pravatar.cc/40?u=carol', alt: 'Carol' } }
];
</script>
<Select items={members} placeholder="Assign to member" />Disabled
Disable the select or individual items.
<script lang="ts">
const plans = [
{ value: 'free', label: 'Free' },
{ value: 'pro', label: 'Pro' },
{ value: 'enterprise', label: 'Enterprise', disabled: true }
];
</script>
<Select items={plans} placeholder="Select a plan" />
<Select items={plans} placeholder="Disabled select" disabled />Multiple Selection
Set multiple to pick more than one option. value becomes a string[], the dropdown stays open after each pick, and the trigger joins labels with separator (default ", ").
<script lang="ts">
import { Select } from 'sv5ui';
let value = $state<string[]>(['us', 'ca']);
// Initialize the value via state instead of a defaultValue prop
let preset = $state<string[]>(['mx', 'br']);
const countries = [
{ value: 'us', label: 'United States' },
{ value: 'ca', label: 'Canada' },
{ value: 'mx', label: 'Mexico' },
{ value: 'br', label: 'Brazil' },
{ value: 'ar', label: 'Argentina' }
];
</script>
<!-- Default separator: ", " -->
<Select items={countries} bind:value multiple placeholder="Pick countries" />
<!-- Custom separator -->
<Select items={countries} bind:value={preset} multiple separator=" • " placeholder="Pick countries" />Multiple with Chips
Render selected values as chips with the selected snippet. It receives { items, remove, clear } - call stopPropagation on remove clicks so the trigger does not toggle.
<script lang="ts">
import { Select, Badge } from 'sv5ui';
let value = $state<string[]>(['react', 'svelte']);
const items = [
{ type: 'label', label: 'Frontend' },
{ value: 'react', label: 'React' },
{ value: 'vue', label: 'Vue' },
{ value: 'svelte', label: 'Svelte' },
{ type: 'separator' },
{ type: 'label', label: 'Backend' },
{ value: 'node', label: 'Node.js' },
{ value: 'python', label: 'Python' },
{ value: 'go', label: 'Go' }
];
</script>
<Select {items} bind:value multiple placeholder="Pick technologies">
{#snippet selected({ items, remove })}
<div class="flex flex-wrap items-center gap-1">
{#each items as item (item.value)}
<Badge
label={item.label}
variant="soft"
size="sm"
trailingIcon="lucide:x"
class="cursor-pointer"
onclick={(e) => { e.stopPropagation(); remove(item.value); }}
/>
{/each}
</div>
{/snippet}
</Select>Form Submission
Give the Select a name, or wrap it in a FormField that has one, and the selection is
submitted with the form like a native select. With multiple,
each value is its own entry, so read it with formData.getAll(name).
required on the Select blocks the submission while
nothing is selected and moves focus to the trigger. required on the FormField only adds the asterisk and aria-required,
so set it on both. Press Submit with nothing selected, then pick values and submit again.
<script lang="ts">
import { Button, FormField, Select } from 'sv5ui';
let country = $state<string>();
let languages = $state<string[]>([]);
function handleSubmit(event: SubmitEvent) {
event.preventDefault();
const data = new FormData(event.currentTarget as HTMLFormElement);
data.get('country'); // 'ca', or '' when nothing is selected
data.getAll('languages'); // ['svelte', 'react'], or [] when nothing is selected
}
</script>
<form onsubmit={handleSubmit}>
<!-- FormField gives the Select its name. required on the Select blocks the submission. -->
<FormField label="Country" name="country" required>
<Select items={countries} bind:value={country} required placeholder="Select a country" />
</FormField>
<FormField label="Languages" name="languages">
<Select items={languageItems} bind:value={languages} multiple placeholder="Pick languages" />
</FormField>
<Button type="submit" label="Submit" />
<Button type="reset" label="Reset" variant="outline" color="surface" />
</form>What Gets Submitted
| Situation | Result |
|---|---|
Single, something selected | One entry: name=value |
Single, nothing selected | One entry with an empty string |
multiple, values selected | One entry per value, in selection order |
multiple, nothing selected | No entry at all |
required and empty | The browser blocks the submission and moves focus to the trigger |
form.reset() | Clears the selection and shows the placeholder again. Unlike a native select, it does not return to the value the component started with |
A value not in items | Not submitted, and required still fails. It submits once items include it |
disabled | Nothing is submitted and nothing is validated |
No name | No input is rendered, so the Select is not part of the form |
Empty Value
An item can use an empty string as its value, for a choice like "Unassigned" or "Any". It is selected only when value is exactly ''; while value is undefined the placeholder shows.
After form.reset() the value is '' again, so the item shows.
Values: "" and undefined
<script lang="ts">
import { Select } from 'sv5ui';
const assignees = [
{ value: '', label: 'Unassigned' },
{ value: 'alice', label: 'Alice Martin' },
{ value: 'bob', label: 'Bob Wilson' }
];
let assignee = $state(''); // shows "Unassigned"
let unset = $state<string>(); // shows the placeholder
</script>
<Select items={assignees} bind:value={assignee} />
<Select items={assignees} bind:value={unset} placeholder="Select an assignee" />UI Slots
Use the ui prop to override classes on internal elements.
| Slot | Description |
|---|---|
root | Outermost container wrapper |
base | Trigger button element |
leading | Leading content wrapper |
leadingIcon | Leading icon element |
leadingAvatar | Leading avatar element |
trailing | Trailing content wrapper |
trailingIcon | Trailing icon (chevron) |
value | Selected value text |
placeholder | Placeholder text |
content | Dropdown content panel |
viewport | Scrollable viewport |
group | Option group wrapper |
groupLabel | Group label text |
item | Individual option |
itemIcon | Icon in option |
itemAvatar | Avatar in option |
itemLabel | Label text in option |
itemDescription | Description in option |
itemIndicator | Selected checkmark |
separator | Separator between groups |
<Select
items={countries}
placeholder="Custom styled"
ui={{
base: 'rounded-full shadow-lg',
content: 'rounded-xl',
item: 'rounded-lg'
}}
/>Snippets
| Snippet | Description |
|---|---|
leadingSlot | Custom content before selected value. Replaced by the spinner while loading |
trailingSlot | Custom content after selected value. Hidden while loading when the spinner is on the trailing side |
selected | Custom rendering of selected value(s) in the trigger (multiple mode). Receives { items, remove, clear } |
item | Custom option rendering (receives item, index, selected) |
itemLeading | Custom option leading (receives item, index, selected) |
itemLabel | Custom option label (receives item, index, selected) |
itemTrailing | Custom option trailing (receives item, index, selected) |
content | Custom dropdown content (receives open) |
Props
| Prop | Type | Default |
|---|---|---|
items | SelectItemType[] | [] |
value | string | string[] | - |
multiple | boolean | false |
separator | string | ', ' |
open | boolean | false |
placeholder | string | - |
variant | 'outline' | 'soft' | 'subtle' | 'ghost' | 'none' | 'outline' |
color | ColorType | 'primary' |
size | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'md' |
highlight | boolean | false |
loading | boolean | false |
disabled | boolean | false |
icon | string | - |
leadingIcon | string | - |
trailingIcon | string | 'lucide:chevron-down' |
selectedIcon | string | 'lucide:check' |
avatar | AvatarProps | - |
required | boolean | false |
name | string | - |
ref | HTMLElement | null | null |
class | string | - |
ui | Record<Slot, Class> | - |
Item Props
Use type: 'label' for group headings and type: 'separator' for dividers.
| Prop | Type | Default |
|---|---|---|
value | string | - |
label | string | - |
description | string | - |
icon | string | - |
avatar | AvatarProps | - |
disabled | boolean | false |