Components
Select
Pick one option from a short list, with full keyboard support and typeahead.
We host the room closest to you.
import { Field } from "@sideby/ui/field";
import * as Select from "@sideby/ui/select";
const regions = [
{ value: "eu", label: "Europe" },
{ value: "na", label: "North America" },
{ value: "apac", label: "Asia Pacific" },
];
let region = $state("");
<Field label="Region" description="We host the room closest to you.">
{#snippet control(attrs)}
<Select.Root type="single" name="region" items={regions} bind:value={region}>
<Select.Trigger {...attrs}>
<Select.Value placeholder="Pick a region" />
</Select.Trigger>
<Select.Content>
<Select.Item value="eu" label="Europe" />
<Select.Item value="na" label="North America" />
<Select.Item value="apac" label="Asia Pacific" />
</Select.Content>
</Select.Root>
{/snippet}
</Field> When to use it
Use a Select to pick one option from a list that is too long to show all at once, about five to fifteen items: a region, a video quality, a subtitle language. With two to four options that people should see side by side, use a toggle group. For an on-off setting, use a switch.
Put it in a Field and spread the Field’s attrs on Select.Trigger, so the label names the trigger and the description and error are tied to it. To make it required, pass required to Select.Root for the form value; the trigger turns the Field’s required into aria-required.
Pass items (value and label pairs) to Select.Root when the select starts with a value, so the trigger can show that value’s label before the list has ever opened.
Groups
Group related options under a heading in the label voice, with a hairline between groups. Bits UI ties each heading to its group, so a screen reader announces the group name as you move into it.
import * as Select from "@sideby/ui/select";
<Select.Root type="single" value="eu-west">
<Select.Trigger aria-label="Server">
<Select.Value placeholder="Pick a server" />
</Select.Trigger>
<Select.Content>
<Select.Group>
<Select.GroupHeading>Europe</Select.GroupHeading>
<Select.Item value="eu-west" label="Frankfurt" />
<Select.Item value="eu-north" label="London" />
</Select.Group>
<Select.Separator />
<Select.Group>
<Select.GroupHeading>North America</Select.GroupHeading>
<Select.Item value="na-east" label="Virginia" />
<Select.Item value="na-west" label="San Jose" />
</Select.Group>
</Select.Content>
</Select.Root> A disabled option
A disabled option stays in the list at half opacity, so people can see it exists, but the keyboard skips it and it cannot be chosen. Say why in the description, not in the option.
4K arrives when the host's link has it.
import { Field } from "@sideby/ui/field";
import * as Select from "@sideby/ui/select";
<Field label="Quality" description="4K arrives when the host's link has it.">
{#snippet control(attrs)}
<Select.Root type="single" value="auto" items={qualities}>
<Select.Trigger {...attrs}>
<Select.Value placeholder="Pick a quality" />
</Select.Trigger>
<Select.Content>
<Select.Item value="auto" label="Auto" />
<Select.Item value="1080" label="1080p" />
<Select.Item value="720" label="720p" />
<Select.Item value="480" label="480p" />
<Select.Item value="4k" label="4K" disabled />
</Select.Content>
</Select.Root>
{/snippet}
</Field> Keyboard
- Enter, Space, Down or Up on the trigger opens the list with the selected option highlighted.
- Up and Down move through the options, skipping disabled ones. Home and End jump to the first and last.
- Typing jumps to the next option whose label starts with what you typed (typeahead).
- Enter or Space chooses the highlighted option and closes the list.
- Escape closes the list without changing the value, and focus goes back to the trigger. Tab closes it too.
Bits UI owns all of this, along with the combobox and listbox roles and aria-expanded, so do not rebuild it.
Accessibility
- The trigger needs a name. Inside a Field it gets one from the label. On its own, give it an
aria-label. - Text is 16px in the trigger (
text-input), the same as an Input, so iOS Safari never zooms. - The selected option shows a check as well as the accent text colour, so the choice never rests on colour alone.
- The trigger edge uses
border-control(3:1 in both themes) and turns red when the Field has an error. The list floats on the popover surface with the only shadow the system allows.
Copy
- Label the choice, not the action: “Region”, “Quality”, “Subtitles”.
- The placeholder asks: “Pick a region”. It shows in muted text until something is chosen.
- Option labels are short nouns in sentence case. Keep them scannable; detail goes in the Field description.