Sina UI

Forms

Select

Chooses one option from a list. Two variants: the browser's own, and a custom list you can style.

Installation

npx sinaui add select custom-select

Which one?

  • Native for plain text options. Phones open their system picker, and it works with no JavaScript. Prefer it.
  • Custom when options need a second line, an icon or a swatch, or the list must match your design exactly.

Native

Copy src/lib/ui/Select.svelte, Icon.svelte and tokens.css.

With a placeholder

The placeholder reads as a hint and can't be chosen back once something is picked.

<script lang="ts">
	import Select from '#lib/ui/Select.svelte';

	let city = $state('');
</script>

<Select label="Center of learning" placeholder="Choose a city" bind:value={city}>
	<option value="baghdad">Baghdad</option>
	<option value="cordoba">Córdoba</option>
	<option value="cairo">Cairo</option>
	<option value="samarkand">Samarkand</option>
</Select>

Grouped options

Grouped by discipline.

<script lang="ts">
	import Select from '#lib/ui/Select.svelte';

	let work = $state('canon');
</script>

<Select label="Work" bind:value={work} hint="Grouped by discipline.">
	<optgroup label="Medicine">
		<option value="canon">The Canon of Medicine</option>
		<option value="tasrif">Kitab al-Tasrif</option>
	</optgroup>
	<optgroup label="Mathematics">
		<option value="jabr">Al-Jabr</option>
	</optgroup>
	<optgroup label="Optics">
		<option value="manazir">Kitab al-Manazir</option>
	</optgroup>
</Select>

With an error

Choose where to read the manuscript.

<script lang="ts">
	import Select from '#lib/ui/Select.svelte';

	let room = $state('');
	const error = $derived(room ? undefined : 'Choose where to read the manuscript.');
</script>

<Select label="Reading room" placeholder="Choose a room" bind:value={room} {error}>
	<option value="baghdad">Bayt al-Hikma, Baghdad</option>
	<option value="fez">Al-Qarawiyyin, Fez</option>
</Select>

Beside other fields

In a row, controls line up even when only one field has a hint.

On the spine, under the title.

<script lang="ts">
	import Input from '#lib/ui/Input.svelte';
	import Select from '#lib/ui/Select.svelte';
</script>

<div class="row">
	<Select label="Collection" value="baghdad">
		<option value="baghdad">Bayt al-Hikma, Baghdad</option>
		<option value="fez">Al-Qarawiyyin, Fez</option>
	</Select>
	<Input label="Call number" value="MS 4192" hint="On the spine, under the title." />
</div>

<style>
	.row {
		display: grid;
		grid-template-columns: repeat(2, minmax(0, 1fr));
		gap: 1rem;
	}
</style>

Label for screen readers only

Where the options say what they are, such as a sort order above a list, hideLabel keeps the label for screen readers only.

<script lang="ts">
	import Select from '#lib/ui/Select.svelte';

	let order = $state('newest');
</script>

<Select label="Sort by" hideLabel bind:value={order}>
	<option value="newest">Newest copies first</option>
	<option value="oldest">Oldest copies first</option>
	<option value="title">By title</option>
</Select>

Custom

Copy src/lib/ui/CustomSelect.svelte, floating.ts, Icon.svelte and tokens.css. No other dependencies.

Basic

Type to jump: several letters in a row search together, so “sam” reaches Samarkand. With a name, a hidden input submits the value.

<script lang="ts">
	import CustomSelect from '#lib/ui/CustomSelect.svelte';

	let city = $state('');
	const cities = [
		{ value: 'baghdad', label: 'Baghdad' },
		{ value: 'bukhara', label: 'Bukhara' },
		{ value: 'cairo', label: 'Cairo' },
		{ value: 'cordoba', label: 'Córdoba' },
		{ value: 'damascus', label: 'Damascus' },
		{ value: 'samarkand', label: 'Samarkand' }
	];
</script>

<CustomSelect
	label="City to visit"
	placeholder="Choose a city"
	options={cities}
	bind:value={city}
	name="city"
/>

With descriptions

A second line per option. Disabled options stay visible but can't be chosen.

Nasta‘liq is being recut.

<script lang="ts">
	import CustomSelect from '#lib/ui/CustomSelect.svelte';

	let script = $state('naskh');
	const scripts = [
		{ value: 'kufic', label: 'Kufic', description: 'Angular; early Qur’an manuscripts.' },
		{
			value: 'naskh',
			label: 'Naskh',
			description: 'Rounded and legible; the scribe’s everyday hand.'
		},
		{
			value: 'thuluth',
			label: 'Thuluth',
			description: 'Tall and sweeping; titles and inscriptions.'
		},
		{
			value: 'nastaliq',
			label: 'Nasta‘liq',
			description: 'Flowing; Persian poetry.',
			disabled: true
		}
	];
</script>

<CustomSelect
	label="Script"
	options={scripts}
	bind:value={script}
	hint="Nasta‘liq is being recut."
/>

Custom rendering

The item snippet renders each option however you like; the check mark and keyboard behavior stay.

<script lang="ts">
	import CustomSelect from '#lib/ui/CustomSelect.svelte';

	let ink = $state('lamp');
	const inks = [
		{ value: 'lamp', label: 'Lamp black', color: '#1b1b1d' },
		{ value: 'gall', label: 'Oak gall', color: '#3d3d42' },
		{ value: 'iron', label: 'Iron gray', color: '#6b6b70' },
		{ value: 'silver', label: 'Silverpoint', color: '#a8a8ae' }
	];
	const colorOf = (v: string) => inks.find((i) => i.value === v)?.color;
</script>

<CustomSelect label="Ink" options={inks} bind:value={ink}>
	{#snippet item(option)}
		<span class="row">
			<span class="swatch" style:background={colorOf(option.value)}></span>
			{option.label}
		</span>
	{/snippet}
</CustomSelect>

<style>
	.row {
		display: flex;
		align-items: center;
		gap: 0.625rem;
	}
	.swatch {
		inline-size: 0.875rem;
		block-size: 0.875rem;
		border-radius: var(--ui-radius-pill);
	}
</style>

Props

Select

PropTypeDefault
labelstring (required)
hideLabelbooleanfalse
hideLabelboolean: keeps the label for screen readers onlyfalse
valuestring, bindable''
placeholder, hint, errorstring
children<option> and <optgroup> elements

CustomSelect

PropTypeDefault
labelstring (required)
hideLabelboolean: label for screen readers onlyfalse
options{ value, label, description?, disabled? }[]
valuestring, bindable''
placeholderstring'Choose…'
namestring: submits via a hidden input
hint, errorstring
disabledbooleanfalse
itemSnippet (option, selected)
searchableboolean: a search box above the list (example)false
searchLabel, emptystring'Search', 'No matches'

Accessibility

  • Native: a real <select> with the platform's picker, keyboard and typeahead.
  • Custom: the WAI-ARIA select-only combobox pattern. Focus stays on the button (role="combobox") and the highlighted option is announced through aria-activedescendant.
  • Both: the same label, hint and error wiring as Input; 16px text so iOS doesn't zoom.
  • Native: focus shows as a colored border and soft halo rather than an offset ring, because Chromium keeps a select's focus ring on after a mouse pick.

Keyboard (custom)

KeyAction
Enter / Space / ↓ / ↑Closed: opens at the current option.
↓ / ↑Open: next / previous option (skips disabled).
Home / End, PageUp / PageDownFirst / last, or ten at a time.
LettersJump to the first match; keep typing to refine.
Enter / Space / TabChooses the highlighted option (Tab also moves on).
EscapeCloses without changing anything.
Introduction
Theming
Changelog
Button
Action button
Confirm button
Copy button
Hold to confirm
Split button
Theme toggle
Calendar
Checkbox
Color picker
Combobox
Date picker
Date range picker
File drop
Form
Input
Mention input
Multi select
Number field
OTP input
Password input
Phone input
Radio cards
Radio group
Rich text editor
Search field
Segmented control
Select
Signature pad
Slider
Switch
Tag input
Upload
Wheel picker
Textarea
Time field
Toggle group
Toolbar
Alert dialog
Command palette
Context menu
Dialog
Drawer
Account menu
Dropdown
Hover card
Popover
Tooltip
Announcement bar
Alert
Empty state
Meter
Progress
Rolling number
Skeleton
Spinner
Toast
Avatar
Avatar group
Badge
Card
Carousel
Chart
Sparkline
World map
Chat
Code block
Data table
Folder
Kbd
Mind map
Resizable panels
Scroll area
Separator
Sortable
Table
Tag group
Virtual list
Audio player
Image
Image compare
Video
Visualizer
Breadcrumb
File tree
Docs navigation
Menubar
Navigation menu
Pagination
Sidebar layout
Stat tabs
Stepper
Tabs
Table of contents
Alarm clock
Clock
Dynamic island
Fluid orb
Hourglass
Stopwatch
Timer
AI chat
AI media
Auth
Board
Booking
Dashboard
Docs
File explorer
Messaging
Notifications
Settings
Studio
Team
Overview
Pricing
Agent chat
Calendar
Voice agent
Mail inbox
CMS
Blog
Marketing site
E-commerce
AI agents
SaaS landing page
SaaS app
Accordion
Dark theme
Light theme