Select
A select picks one or more values from a list. It renders one focused element with role="combobox" (a <div>, or an <input> when it searches) and a list in a panel that is put at the end of the page, so its container never cuts it off. SelectOption and SelectOptGroup are the markup form of options.
When to use
- Use a select to pick one value, or several, from a list that is too long for radio buttons or checkboxes.
- Turn on
showSearchwhen the list is long, and usemode="tags"when the user may add values of their own. - For two or three options a group of radio buttons or checkboxes is easier to read at a glance.
Examples
Pick a city
<script lang="ts">
import { Select } from 'svelte-ant-design';
import type { SelectValue } from 'svelte-ant-design';
let city = $state<SelectValue | undefined>();
let last = $state('no change yet');
// A string or a number is both the value and the label; an object gives them apart.
const cities = [
'Bishkek',
'Almaty',
{ value: 'tashkent', label: 'Tashkent' },
{ value: 'ulaanbaatar', label: 'Ulaanbaatar', disabled: true }
];
</script>
<!-- bind:value keeps a variable in sync with the field; onchange receives the value and the option object. -->
<Select
bind:value={city}
aria-label="City"
placeholder="Pick a city"
options={cities}
style="width: 240px"
onchange={(value, option) => (last = `onchange(${JSON.stringify(value)}, ${JSON.stringify(option)})`)}
/>
<span>The city is {city === undefined ? 'not chosen' : city}</span>
<span role="status">{last}</span>
Search a person
Label starts with ...
Type cat, dog, bird or fish
<script lang="ts">
import { Select } from 'svelte-ant-design';
import type { SelectValue } from 'svelte-ant-design';
const people = [
{ value: 'ada', label: 'Ada Lovelace', team: 'analytics' },
{ value: 'grace', label: 'Grace Hopper', team: 'compilers' },
{ value: 'linus', label: 'Linus Torvalds', team: 'kernel' },
{ value: 'margaret', label: 'Margaret Hamilton', team: 'flight software' },
{ value: 'dennis', label: 'Dennis Ritchie', team: 'compilers' }
];
let person = $state<SelectValue | undefined>();
let text = $state('');
let heard = $state('');
// Server-side search: the list is the answer of a (here, pretend) server, so the field does not filter it itself.
let found = $state<{ value: string; label: string }[]>([]);
let busy = $state(false);
let remote = $state<SelectValue | undefined>();
let timer: ReturnType<typeof setTimeout> | undefined;
function search(query: string): void {
clearTimeout(timer);
if (query === '') {
found = [];
busy = false;
return;
}
busy = true;
timer = setTimeout(() => {
found = ['cats', 'dogs', 'birds', 'fish'].filter((word) => word.includes(query.toLowerCase())).map((word) => ({ value: word, label: `${word} (${query})` }));
busy = false;
}, 400);
}
</script>
<!-- showSearch filters by label; optionFilterProp names more fields; filterSort orders the matches. -->
<Select
bind:value={person}
bind:searchValue={text}
aria-label="Person"
placeholder="Search a person"
showSearch
options={people}
optionFilterProp={['label', 'team']}
filterSort={(a, b) => String(a.label).localeCompare(String(b.label))}
notFoundContent="Nobody found"
resultsText={(count) => `${count} found`}
onsearch={(value) => (heard = `onsearch("${value}")`)}
style="width: 280px"
/>
<span>search text: "{text}"</span>
<span role="status">{heard}</span>
<!-- A function decides per option: here the text must start the label. -->
<Select
aria-label="Starts with"
placeholder="Label starts with ..."
showSearch
options={people}
filterOption={(input, option) => String(option.label).toLowerCase().startsWith(input.toLowerCase())}
style="width: 280px"
/>
<!-- filterOption={false} leaves the list to you; loading shows that it is on the way. -->
<!-- autocomplete defaults to "new-password", so browsers do not offer saved values in the search box. -->
<Select
bind:value={remote}
aria-label="Remote search"
placeholder="Type cat, dog, bird or fish"
showSearch
filterOption={false}
loading={busy}
options={found}
onsearch={search}
autocomplete="off"
style="width: 280px"
/>
Svelte TypeScript Svelte, TypeScript
Rust Rust
Svelte Rust + more Svelte, Rust, Go, Python, Kotlin
Type, then pick several
<script lang="ts">
import { Select } from 'svelte-ant-design';
import type { SelectValue } from 'svelte-ant-design';
const languages = ['Svelte', 'TypeScript', 'JavaScript', 'Rust', 'Go', 'Python', 'Kotlin', 'Margaret Hamilton\'s Apollo assembly'];
let chosen = $state<SelectValue[]>(['Svelte', 'TypeScript']);
let removed = $state('nothing removed yet');
let limited = $state<SelectValue[]>(['Rust']);
let kept = $state<SelectValue[]>(['Svelte', 'Rust', 'Go', 'Python', 'Kotlin']);
let typed = $state<SelectValue[]>([]);
</script>
<!-- The value is an array; each value is a tag with a remove button. ondeselect runs when one is removed. -->
<Select
bind:value={chosen}
aria-label="Languages"
mode="multiple"
placeholder="Pick languages"
options={languages}
allowClear
ondeselect={(value) => (removed = `removed ${value}`)}
style="width: 320px"
/>
<span>{JSON.stringify(chosen)}</span>
<span role="status">{removed}</span>
<!-- maxCount: with two values the other options are disabled. -->
<Select
bind:value={limited}
aria-label="At most two"
mode="multiple"
maxCount={2}
options={languages}
style="width: 320px"
/>
<!-- maxTagCount folds the rest into one tag; maxTagTextLength cuts a long tag. -->
<Select
bind:value={kept}
aria-label="Folded tags"
mode="multiple"
maxTagCount={2}
maxTagPlaceholder="+ more"
maxTagTextLength={8}
options={languages}
style="width: 320px"
/>
<!-- autoClearSearchValue={false}: the text stays after a selection, so several matches can be picked in a row. -->
<Select
bind:value={typed}
aria-label="Keep the search text"
mode="multiple"
autoClearSearchValue={false}
placeholder="Type, then pick several"
options={languages}
style="width: 320px"
/>
svelte svelte
Type or paste: red, green, blue
<script lang="ts">
import { Select } from 'svelte-ant-design';
import type { SelectValue } from 'svelte-ant-design';
let tags = $state<SelectValue[]>(['svelte']);
let pasted = $state<SelectValue[]>([]);
</script>
<!-- mode="tags": Enter adds the typed text as a value, even when it is not in the list. -->
<Select
bind:value={tags}
aria-label="Tags"
mode="tags"
placeholder="Type a tag and press Enter"
options={['svelte', 'typescript', 'a11y']}
style="width: 320px"
/>
<span>{JSON.stringify(tags)}</span>
<!-- tokenSeparators: a comma ends a token; a pasted "red, green, blue" becomes three values. -->
<Select
bind:value={pasted}
aria-label="Comma separated tags"
mode="tags"
tokenSeparators={[',']}
placeholder="Type or paste: red, green, blue"
style="width: 320px"
/>
<span>{JSON.stringify(pasted)}</span>
Apple
Apple
Apple
Apple
Apple
outlined
filled
borderless
underlined
error
warning
Apple
prefix
suffix
no suffix
loading
loadingIcon
Banana
Apple Cherry Apple, Cherry
<script lang="ts">
import { Select } from 'svelte-ant-design';
const fruit = ['Apple', 'Banana', 'Cherry'];
let cleared = $state<string | number | undefined>('Banana');
</script>
{#snippet star()}<span aria-hidden="true">★</span>{/snippet}
{#snippet wait()}<span aria-hidden="true">…</span>{/snippet}
{#snippet mark()}<span aria-hidden="true">✔</span>{/snippet}
{#snippet minus()}<span aria-hidden="true">−</span>{/snippet}
<!-- large is 40px high, medium 32px, small 24px; middle and default are aliases of medium. -->
<Select aria-label="Large" size="large" options={fruit} value="Apple" style="width: 160px" />
<Select aria-label="Medium" size="medium" options={fruit} value="Apple" style="width: 160px" />
<Select aria-label="Middle, an alias of medium" size="middle" options={fruit} value="Apple" style="width: 160px" />
<Select aria-label="Default, an alias of medium" size="default" options={fruit} value="Apple" style="width: 160px" />
<Select aria-label="Small" size="small" options={fruit} value="Apple" style="width: 160px" />
<!-- Four variants, two statuses. -->
<Select aria-label="Outlined" variant="outlined" options={fruit} placeholder="outlined" style="width: 160px" />
<Select aria-label="Filled" variant="filled" options={fruit} placeholder="filled" style="width: 160px" />
<Select aria-label="Borderless" variant="borderless" options={fruit} placeholder="borderless" style="width: 160px" />
<Select aria-label="Underlined" variant="underlined" options={fruit} placeholder="underlined" style="width: 160px" />
<Select aria-label="Error" status="error" options={fruit} placeholder="error" style="width: 160px" />
<Select aria-label="Warning" status="warning" options={fruit} placeholder="warning" style="width: 160px" />
<Select aria-label="Disabled" disabled options={fruit} value="Apple" style="width: 160px" />
<!-- prefix, a custom suffix (null hides it), custom icons, and loading, which takes the place of the arrow. -->
<Select aria-label="With a prefix" prefix={star} options={fruit} placeholder="prefix" style="width: 160px" />
<Select aria-label="Custom suffix" suffix="▾" options={fruit} placeholder="suffix" style="width: 160px" />
<Select aria-label="No suffix" suffix={null} options={fruit} placeholder="no suffix" style="width: 160px" />
<Select aria-label="Loading" loading options={fruit} placeholder="loading" style="width: 160px" />
<Select aria-label="Loading with an icon of your own" loading loadingIcon={wait} options={fruit} placeholder="loadingIcon" style="width: 160px" />
<Select
bind:value={cleared}
aria-label="Clearable"
allowClear={{ label: 'Forget the fruit', clearIcon: minus }}
menuItemSelectedIcon={mark}
options={fruit}
style="width: 200px"
/>
<Select
aria-label="Tags with a custom remove icon"
mode="multiple"
removeIcon="×"
options={fruit}
value={['Apple', 'Cherry']}
style="width: 240px"
/>
Pick a person
Kyrgyzstan
<script lang="ts">
import { Select } from 'svelte-ant-design';
import type { SelectValue } from 'svelte-ant-design';
// An entry with an options array is a group. A disabled option is shown and cannot be chosen.
const people = [
{
label: 'Engineers',
options: [
{ value: 'ada', label: 'Ada' },
{ value: 'linus', label: 'Linus' }
]
},
{
label: 'Scientists',
options: [
{ value: 'grace', label: 'Grace' },
{ value: 'barbara', label: 'Barbara', disabled: true }
]
}
];
// fieldNames maps the keys of your own data: here { id, name } instead of { value, label }.
const countries = [
{ name: 'Asia', members: [{ id: 'kg', name: 'Kyrgyzstan' }, { id: 'kz', name: 'Kazakhstan' }] },
{ name: 'Europe', members: [{ id: 'fr', name: 'France' }] }
];
let person = $state<SelectValue | undefined>();
let country = $state<SelectValue | undefined>('kg');
</script>
<Select bind:value={person} aria-label="Person" placeholder="Pick a person" showSearch options={people} style="width: 240px" />
<span>{JSON.stringify(person)}</span>
<Select
bind:value={country}
aria-label="Country"
options={countries}
fieldNames={{ label: 'name', value: 'id', options: 'members' }}
style="width: 240px"
/>
<span>{JSON.stringify(country)}</span>
🧮 Ada Lovelace
Linus Torvalds Linus Torvalds
<script lang="ts">
import type { Snippet } from 'svelte';
import { Button, Select } from 'svelte-ant-design';
import type { SelectOptionItem, SelectTag, SelectValue } from 'svelte-ant-design';
const people = [
{ value: 'ada', label: 'Ada Lovelace', role: 'mathematician', emoji: '🧮' },
{ value: 'grace', label: 'Grace Hopper', role: 'rear admiral', emoji: '⚓' },
{ value: 'linus', label: 'Linus Torvalds', role: 'kernel maintainer', emoji: '🐧' }
];
let one = $state<SelectValue | undefined>('ada');
let tagged = $state<SelectValue[]>(['linus']);
let wrapped = $state<SelectValue | undefined>();
let presses = $state(0);
</script>
<!-- optionRender draws an option in the list (the field keeps the plain label); labelRender draws the selected value. -->
{#snippet row(option: SelectOptionItem, index: number)}
<span>{option.emoji} <strong>{option.label}</strong> <small>{option.role} (#{index + 1})</small></span>
{/snippet}
{#snippet chosen(option: SelectOptionItem)}<span>{option.emoji} {option.label}</span>{/snippet}
<Select
bind:value={one}
aria-label="Person"
options={people}
optionRender={row}
labelRender={chosen}
popupMatchSelectWidth={320}
style="width: 240px"
/>
<!-- tagRender draws a tag; onclose removes the value, closable says whether it may be removed. -->
{#snippet tag({ value, label, closable, onclose }: SelectTag)}
<span class="chip" data-value={value}>
{label}
{#if closable}<button type="button" aria-label="Remove {value}" onclick={onclose}>×</button>{/if}
</span>
{/snippet}
<Select bind:value={tagged} aria-label="Custom tags" mode="multiple" options={people} tagRender={tag} style="width: 320px" />
<!-- popupRender wraps the list; a press on the button does not take focus from the field or close the list. -->
{#snippet panel(list: Snippet)}
<div>
{@render list()}
<div class="panel-foot">
<Button size="small" onclick={() => presses++}>Add a person ({presses})</Button>
</div>
</div>
{/snippet}
<Select bind:value={wrapped} aria-label="With a footer" options={people} popupRender={panel} style="width: 240px" />
<style>
.chip {
display: inline-flex;
gap: 4px;
align-items: center;
padding: 0 6px;
border: 1px solid var(--ads-color-border);
border-radius: 4px;
}
.chip button {
padding: 0;
border: 0;
background: none;
color: inherit;
cursor: pointer;
}
.panel-foot {
padding: 4px;
border-top: 1px solid var(--ads-color-border-secondary);
}
</style>
bottomLeft
Open me
360px list
false
listHeight 120
Controlled
container
<script lang="ts">
import { Button, Select } from 'svelte-ant-design';
import type { SelectPlacement, SelectValue } from 'svelte-ant-design';
const moods = [
{ value: 'happy', label: 'Happy' },
{ value: 'sad', label: 'Sad' },
{ value: 'long', label: 'A rather long label that needs a wider list than the field' }
];
const many = Array.from({ length: 40 }, (_, index) => ({ value: index, label: `Option ${index + 1}` }));
let placement = $state<SelectValue | undefined>('bottomLeft');
let open = $state(false);
let log = $state('nothing yet');
let scrolled = $state(0);
let host = $state<HTMLElement>();
</script>
<!-- placement: the preferred side; the list flips at the edge of the screen. -->
<Select
aria-label="Choose the placement"
bind:value={placement}
options={['bottomLeft', 'bottomRight', 'topLeft', 'topRight']}
style="width: 200px"
/>
<Select aria-label="Placement" placement={placement as SelectPlacement} options={moods} placeholder="Open me" style="width: 200px" />
<!-- popupMatchSelectWidth: a number is a width in px (never narrower than the field), false fits the content. -->
<Select aria-label="A wider list" popupMatchSelectWidth={360} options={moods} placeholder="360px list" style="width: 160px" />
<Select aria-label="A list as wide as its content" popupMatchSelectWidth={false} options={moods} placeholder="false" style="width: 160px" />
<!-- listHeight: the list is at most this high and scrolls. onpopupscroll reports it. -->
<Select
aria-label="A short list"
listHeight={120}
options={many}
placeholder="listHeight 120"
onpopupscroll={() => (scrolled += 1)}
style="width: 200px"
/>
<span>scroll events: {scrolled}</span>
<!-- bind:open controls the list; onopenchange reports the changes the user makes. -->
<Select
bind:open
aria-label="Controlled list"
options={moods}
placeholder="Controlled"
onopenchange={(value) => (log = `onopenchange(${value})`)}
style="width: 200px"
/>
<Button onclick={() => (open = !open)}>{open ? 'Close' : 'Open'} from the page</Button>
<span role="status">{log}</span>
<!-- container: where the panel is put. Here, into a box of the page instead of the end of the body. -->
<Select aria-label="In a box" container={() => host!} options={moods} placeholder="container" style="width: 200px" />
<div bind:this={host} class="host"></div>
<style>
.host {
position: relative;
min-height: 8px;
}
</style>
Free
Choose, clear, tab away
<script lang="ts">
import { Checkbox, Select } from 'svelte-ant-design';
import type { SelectValue } from 'svelte-ant-design';
const plans = [
{ value: 'free', label: 'Free' },
{ value: 'pro', label: 'Pro' },
{ value: 'team', label: 'Team' }
];
let plan = $state<SelectValue | undefined>('free');
let locked = $state(true);
let log = $state<string[]>([]);
let quiet = $state<SelectValue | undefined>();
const note = (text: string) => (log = [...log.slice(-3), text]);
</script>
<!-- A function binding decides what the field may change to: while "locked" is on, every change is refused. -->
<Select
bind:value={
() => plan,
(next) => {
if (!locked) plan = next;
}
}
aria-label="Plan"
options={plans}
style="width: 200px"
/>
<Checkbox bind:checked={locked}>The plan is locked</Checkbox>
<span>{JSON.stringify(plan)}</span>
<!-- The callbacks report what the user does, in this order: onselect, then onchange; onclear after a clear. -->
<!-- onkeydown and oninput are the native handlers of the focused element; oninputkeydown is the same key, as a callback of the Select. -->
<Select
bind:value={quiet}
aria-label="Plan, with callbacks"
allowClear
showSearch
options={plans}
placeholder="Choose, clear, tab away"
onselect={(value) => note(`onselect(${value})`)}
onchange={(value) => note(`onchange(${JSON.stringify(value)})`)}
onclear={() => note('onclear()')}
onfocus={() => note('onfocus')}
onblur={() => note('onblur')}
onkeydown={() => note('onkeydown')}
oninput={() => note('oninput')}
oninputkeydown={(event) => note(`oninputkeydown(${event.key})`)}
defaultActiveFirstOption={false}
style="width: 240px"
/>
<ol class="log" aria-label="Callbacks">
{#each log as entry, index (index)}<li>{entry}</li>{/each}
</ol>
<style>
.log {
margin: 0;
padding-inline-start: 20px;
font-family: monospace;
font-size: 12px;
}
</style>
label for
aria-label
aria-labelledby
Banana Banana
<script lang="ts">
import { Select } from 'svelte-ant-design';
const fruit = ['Apple', 'Banana', 'Cherry'];
</script>
<!-- A Select has no label of its own: name it with an external label, aria-label or aria-labelledby. -->
<!-- The label also names a field that does not search, which a native label could not do for a <div>. -->
<label for="select-labels-fruit">Fruit</label>
<Select id="select-labels-fruit" options={fruit} placeholder="label for" style="width: 200px" />
<Select aria-label="Favourite fruit" options={fruit} placeholder="aria-label" style="width: 200px" />
<span id="select-labels-colour">Colour</span>
<Select
aria-labelledby="select-labels-colour"
aria-describedby="select-labels-colour-hint"
options={['Red', 'Green']}
placeholder="aria-labelledby"
style="width: 200px"
/>
<small id="select-labels-colour-hint">The colour of the fruit</small>
<!-- The search input is a native input, so a label names it natively. aria-describedby adds the selected text after your ids. -->
<label for="select-labels-search">Search a fruit</label>
<Select id="select-labels-search" showSearch options={fruit} value="Banana" style="width: 200px" />
🍎
Apple Apple
<script lang="ts">
import { Select } from 'svelte-ant-design';
</script>
<!-- classNames adds a class to a part, styles adds inline styles to it; numbers are written as they are. -->
<!-- popup, list and listItem are in the panel; item is a selected value or a tag. -->
<Select
aria-label="Styled parts"
mode="multiple"
allowClear
prefix="🍎"
placeholder="Pick fruit"
options={['Apple', 'Banana', 'Cherry']}
value={['Apple']}
class="semantic-select"
style="width: 320px"
classNames={{ root: 'semantic-root', item: 'semantic-item', popup: 'semantic-popup', listItem: 'semantic-option' }}
styles={{
root: { 'border-style': 'dashed' },
prefix: { 'margin-inline-end': '8px' },
content: { 'padding-block': '1px' },
placeholder: { 'font-style': 'italic' },
item: { 'font-weight': 600 },
clear: { color: 'crimson' },
input: { 'letter-spacing': '0.5px' },
suffix: { opacity: 0.6 },
popup: { 'border-radius': '12px' },
list: { 'padding-block': '2px' },
listItem: { 'font-variant': 'small-caps' }
}}
/>
<style>
:global(.semantic-popup) {
outline: 1px dashed var(--ads-color-border);
}
:global(.semantic-item) {
letter-spacing: 0.2px;
}
</style>
Option B
<script lang="ts">
import { Button, Select, SelectOption, SelectOptGroup } from 'svelte-ant-design';
import type { SelectValue } from 'svelte-ant-design';
let value = $state<SelectValue | undefined>('b');
let extra = $state(false);
let keys = $state(['b', 'c', 'd']);
let ignored = $state<SelectValue | undefined>();
</script>
{#snippet bold()}<b>Rich</b> content{/snippet}
<!-- SelectOption and SelectOptGroup written inside Select give the options, in the order of the markup. -->
<Select bind:value aria-label="Options as markup" style="width: 240px">
<SelectOption value="a" label="Option A" />
{#if extra}<SelectOption value="m" label="Inserted in the middle" />{/if}
<SelectOptGroup label="A group" title="About the group" class="markup-group">
{#each keys as key (key)}
<SelectOption value={key} label={`Option ${key.toUpperCase()}`} />
{/each}
</SelectOptGroup>
<SelectOption value="rich" label="Rich option" title="Searched by its label" class="markup-option">{@render bold()}</SelectOption>
<SelectOption value="off" label="Not available" disabled />
</Select>
<span>{JSON.stringify(value)}</span>
<Button onclick={() => (extra = !extra)}>{extra ? 'Remove' : 'Insert'} an option</Button>
<Button onclick={() => (keys = [...keys].reverse())}>Reverse the group</Button>
<!-- A non-empty options prop wins: the children are ignored. -->
<Select bind:value={ignored} aria-label="Options win" options={['from options']} style="width: 240px">
<SelectOption value="ignored" label="Ignored" />
</Select>
<style>
:global(.markup-option) {
font-style: italic;
}
:global(.markup-group) {
border-top: 1px dashed var(--ads-color-border);
}
</style>
maxTagCount="responsive" (drag the corner to change the width)
Ada Lovelace Grace Hopper Linus Torvalds Margaret Hamilton Dennis Ritchie + 1 ... Ada Lovelace, Grace Hopper, Linus Torvalds, Margaret Hamilton, Dennis Ritchie
maxTagPlaceholder
Ada Lovelace Grace Hopper Linus Torvalds Margaret Hamilton Dennis Ritchie Barbara Liskov 1 more Ada Lovelace, Grace Hopper, Linus Torvalds, Margaret Hamilton, Dennis Ritchie, Barbara Liskov
<script lang="ts">
import { Select } from 'svelte-ant-design';
import type { SelectValue } from 'svelte-ant-design';
const people = ['Ada Lovelace', 'Grace Hopper', 'Linus Torvalds', 'Margaret Hamilton', 'Dennis Ritchie', 'Barbara Liskov', 'Ken Thompson', 'Radia Perlman'];
let team = $state<SelectValue[]>(people.slice(0, 5));
let reviewers = $state<SelectValue[]>(people.slice(0, 6));
</script>
<div class="stack">
<div class="field">
<span class="caption">maxTagCount="responsive" (drag the corner to change the width)</span>
<!-- One row: as many tags as fit, the rest in the last tag; typed text takes room from the tags. -->
<div class="resizable">
<Select bind:value={team} aria-label="Team" mode="multiple" maxTagCount="responsive" options={people} placeholder="Pick people" allowClear />
</div>
</div>
<div class="field">
<span class="caption">maxTagPlaceholder</span>
<!-- The snippet gets the hidden options. -->
<Select bind:value={reviewers} aria-label="Reviewers" mode="multiple" maxTagCount="responsive" options={people} style="width: 320px; max-width: 100%">
{#snippet maxTagPlaceholder(hidden)}
<span title={hidden.map((option) => option.label).join(', ')}>{hidden.length} more</span>
{/snippet}
</Select>
</div>
</div>
<style>
.stack {
display: grid;
gap: 16px;
width: 100%;
}
.field {
display: grid;
/* The column is as wide as the demo, not as the fields in it ask: on a phone they shrink with it. */
grid-template-columns: minmax(0, 1fr);
justify-items: start;
gap: 6px;
min-width: 0;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
/* The padding leaves room for the shadow of the focused field inside the box that clips. */
.resizable {
box-sizing: border-box;
width: 380px;
min-width: 140px;
max-width: calc(100% + 4px);
margin-inline-start: -4px;
padding: 4px 16px 4px 4px;
overflow: hidden;
resize: horizontal;
}
</style>
API
| Property | Description | Type | Default |
|---|---|---|---|
| value | The selected value: one value, or an array in multiple and tags. Use bind:value; a plain value is the initial one. A function binding can refuse a change. undefined and null mean nothing is selected; a value that matches no option is shown as its own text. | SelectValue | SelectValue[] | null | — |
| mode | multiple and tags take an array; in tags a typed text can become a value. default (the Angular name) is the single mode. | 'multiple' | 'tags' | 'default' | 'default' |
| options | The options. A string or a number is both the value and the label; an entry with an options array is a group. Values must be unique. The last type is for fieldNames: objects whose keys are not label and value. | ReadonlyArray<SelectValue | SelectOptionItem | SelectOptionGroup | Record<string, unknown>> | [] |
| fieldNames | Maps the keys of the objects in options. groupLabel follows the mapped label key unless it is set. | { label?: string; value?: string; options?: string; groupLabel?: string } | — |
| placeholder | Shown while nothing is selected. It is not a label: the field still needs an accessible name. | string | Snippet | — |
| disabled | Not focusable, does not open; the clear button and the icons use the disabled colors. | boolean | false |
| loading | A spinner takes the place of the arrow (or of a custom suffix); the width does not change. Sets aria-busy. The list stays usable. | boolean | false |
| size | Size of the field: 40px, 32px or 24px high. middle and default are compatibility aliases of medium. In a SpaceCompact a control without a size takes the one of the block. | 'large' | 'medium' | 'middle' | 'small' | 'default' | 'medium' |
| variant | Visual variant. The borderless field draws a focus outline. | 'outlined' | 'filled' | 'borderless' | 'underlined' | 'outlined' |
| status | Validation look. error also sets aria-invalid="true"; warning changes only the look. | 'error' | 'warning' | — |
| prefix | Content before the selection, inside the border: plain text or a snippet. | string | Snippet | — |
| suffix | Replaces the arrow (the default); null hides it. A press on it opens the list like the rest of the field. | string | Snippet | null | — |
| allowClear | Shows a native clear button while there is a selection (not while disabled). A press keeps focus in the field and calls onchange, then onclear. The object form sets the icon, the accessible name (default Clear) and the tab index. | boolean | { clearIcon?: string | Snippet; label?: string; tabIndex?: number } | false |
| removeIcon | Replaces the cross on a tag. | string | Snippet | — |
| menuItemSelectedIcon | The mark on a selected option in the list. By default the check mark shows in multiple and tags only; with this prop a single field shows it too. | string | Snippet | — |
| loadingIcon | Replaces the spinner shown while loading. | string | Snippet | — |
| showSearch | Makes the focused element a text input that filters the list. Default: off in the single mode, on in multiple and tags. | boolean | — |
| searchValue | The current search text. Use bind:searchValue. It is cleared when the list closes. | string | '' |
| onsearch | Called on every change of the search text: an edit, a token separator, and when the component clears the text (on close, on blur, after a selection with autoClearSearchValue). | (value: string) => void | — |
| filterOption | true filters by optionFilterProp; a function decides per option; false leaves the list as given (server-side search). | boolean | ((input: string, option: SelectOptionItem) => boolean) | true |
| filterSort | Orders the filtered options. The third argument carries the search text. | (a: SelectOptionItem, b: SelectOptionItem, info: { searchValue: string }) => number | — |
| optionFilterProp | Which fields of an option the text is matched against (case-insensitive "contains"). label is the text of the option; several fields match with OR. | string | string[] | 'label' |
| autoClearSearchValue | multiple and tags: clear the search text after a selection. | boolean | true |
| maxTagCount | multiple and tags: show this many tags, the rest collapse into one tag, + N .... 'responsive': one row with as many tags as fit. | number | 'responsive' | — |
| maxTagPlaceholder | The content of the collapsed tag; a snippet gets the omitted options. | string | Snippet<[omitted: SelectOptionItem[]]> | — |
| maxTagTextLength | A longer tag text is cut with an ellipsis (the accessible name of its remove button keeps the whole text). | number | — |
| maxCount | multiple and tags: at most this many values; while it is reached the other options are disabled. No effect in the single mode. | number | — |
| tokenSeparators | multiple and tags: typed or pasted text is split at these characters into values. In tags every part is a value; in multiple a part that matches no option is dropped. Values beyond maxCount are dropped. | string[] | [] |
| tagRender | A custom tag. closable is false for a disabled field or option; onclose removes the value. A press on your own close control does not open the list when it is a button. | Snippet<[tag: { value: SelectValue; label: string | number | Snippet; closable: boolean; onclose: () => void }]> | — |
| optionRender | The content of an option in the list; the field keeps the plain label. | Snippet<[option: SelectOptionItem, index: number]> | — |
| labelRender | The content of the selected value in the field, and of the tags. | Snippet<[option: SelectOptionItem]> | — |
| notFoundContent | Shown in the panel when no option remains. While searching, the status line reads the same text out (it takes it from the element, so a snippet works too). The default text is No data. | string | Snippet | — |
| resultsText | The text of the polite status line that announces the number of matches while searching: 1 result, N results by default. It is written 300 ms after the list stopped changing, and after an IME composition ends. With no match the line says the notFoundContent text instead of a number. | (count: number) => string | — |
| open | The list is shown. Use bind:open for controlled use. A disabled field never shows it. | boolean | false |
| onopenchange | Called once per change of the open state caused by the user, not for a change made by the parent. | (open: boolean) => void | — |
| placement | The preferred side of the list; it flips at the edge of the screen and mirrors in right-to-left layouts. | 'bottomLeft' | 'bottomRight' | 'topLeft' | 'topRight' | 'bottomLeft' |
| popupMatchSelectWidth | true: the list is at least as wide as the field. A number: that width in px, never narrower than the field. false: as wide as its content. | boolean | number | true |
| listHeight | The maximum height of the list in px; it scrolls beyond that. A long list renders all its options (no virtual scrolling yet). | number | 256 |
| container | Where the panel is put: an element, or a function that gets the field and returns one. A Select inside another popup passes the parent of its field. | HTMLElement | ((anchor: HTMLElement | null) => HTMLElement) | — |
| popupRender | Wraps the list with your own content. A press in the added content does not take focus from the field (inputs in it still work). | Snippet<[list: Snippet]> | — |
| defaultActiveFirstOption | Highlight the first option when the list opens or the filter changes. A single field highlights its selected option on opening either way. | boolean | true |
| onchange | Called once per user change with the new value and the option object(s); not for a change made by the parent. After a clear both are undefined (single) or []. A new tag has { value: text, label: text }. | (value: SelectValue | SelectValue[] | undefined, option: SelectOptionItem | SelectOptionItem[] | undefined) => void | — |
| onselect | A value was selected. Runs before onchange. | (value: SelectValue, option: SelectOptionItem) => void | — |
| ondeselect | multiple and tags: a value was removed. Runs before onchange. | (value: SelectValue, option: SelectOptionItem) => void | — |
| onclear | Called after the clear button emptied the value (after onchange). | () => void | — |
| onfocus | Focus entered the field. Moving it between the field, its clear button and its own panel does not count. | (event: FocusEvent) => void | — |
| onblur | Focus left the field (and the list closes). | (event: FocusEvent) => void | — |
| onpopupscroll | The list scrolled. | (event: Event) => void | — |
| oninputkeydown | A key went down in the focused element, before the field handles it. | (event: KeyboardEvent) => void | — |
| onkeydown / oninput | Native handlers of the focused element; they are called before the component's own (oninput only while it searches). | (event) => void | — |
| autocomplete | autocomplete of the search input. The default new-password stops browsers from offering saved values in the search box. | string | 'new-password' |
| children | SelectOption and SelectOptGroup written as markup; ignored when options has entries. | Snippet | — |
| classNames | Extra classes for the parts, appended to the component's own. The parts popup, list and listItem are in the panel. | Partial<Record<'root' | 'prefix' | 'content' | 'placeholder' | 'item' | 'clear' | 'input' | 'suffix' | 'popup' | 'list' | 'listItem', string>> | — |
| styles | Inline styles for the parts. Property names are kebab-case or custom properties, numbers are written as they are (no automatic px). They win over the component's styles. | Partial<Record<'root' | 'prefix' | 'content' | 'placeholder' | 'item' | 'clear' | 'input' | 'suffix' | 'popup' | 'list' | 'listItem', Record<string, string | number>>> | — |
| class | An additional CSS class for the root. The field fills its container like Input; set the width with class or style. | string | — |
| style | Inline style of the root; styles.root is written after it. | string | — |
| native attributes | id (so <label for> works), aria-label, aria-labelledby, aria-describedby, aria-invalid, tabindex, title, data-* and the other attributes go to the focused element. The component owns role, aria-expanded, aria-controls, aria-activedescendant, aria-autocomplete and aria-busy. | HTMLAttributes<HTMLElement> | — |
Differences from Ant Design:
showSearch is a boolean and the search props are flat (filterOption, searchValue, onsearch ...), where React 6 nests them in an object; there is no defaultValue or defaultOpen, because bind: covers them; suffix replaces suffixIcon and showArrow; values are strings or numbers (no labelInValue yet); the list is not virtual yet, so a very long list renders all its options (virtual is planned); the built-in texts (No data, Clear, Remove …) are English (a locale mechanism is planned); the field fills its container like Input; the type of an option object is SelectOptionItem, because SelectOption is the component.SelectOption API
| Property | Description | Type | Default |
|---|---|---|---|
| value | The value of the option; required and unique within the Select. | SelectValue | — |
| label | What is drawn, and the text of the option for the search and the type-ahead: a string, or (a snippet) drawn only; then the title, then the value is the text. | string | number | Snippet | — |
| disabled | The option is shown, skipped by the arrow keys and cannot be selected. | boolean | — |
| title | Native title of the option; also its text when label is not a string. | string | — |
| class | An extra class of the option in the list. | string | — |
| children | The content of the item in the list. When label is given too, this is drawn and label is still the text. | Snippet | — |
SelectOptGroup API
| Property | Description | Type | Default |
|---|---|---|---|
| label | The label of the group; it names the group for assistive technology. It is not an option. | string | number | Snippet | — |
| title | Native title of the group label. | string | — |
| class | An extra class of the group. | string | — |
| children | The SelectOptions of the group. | Snippet | — |
Methods
Through bind:this. The list does not open on focus.
| Method | Description | Type |
|---|---|---|
| focus | Moves focus into the field (the text input when it searches). The list does not open. | (options?: { preventScroll?: boolean }) => void |
| blur | Removes focus from the field; the list closes. | () => void |
Design tokens
| Token | Description | Default |
|---|---|---|
| --ads-select-icon-size | Size of the arrow, the clear icon and the mark of a selected option. | 12px |
| --ads-select-gap | Distance between the text and the arrow or the clear button. | 6px |
| --ads-select-multiple-padding-block | Vertical padding of a field with tags; with the tag height it gives the 40, 32 and 24px of the sizes for one row. | 3px |
| --ads-select-multiple-padding-inline | Horizontal padding of a field with tags. | 4px |
| --ads-select-tag-height | Height of a tag in a medium field. | 24px |
| --ads-select-tag-height-lg | Height of a tag in a large field. | 32px |
| --ads-select-tag-height-sm | Height of a tag in a small field. | 16px |
| --ads-select-tag-radius | Corner radius of a tag. | 4px |
| --ads-select-tag-gap | Distance between tags, between the rows of tags, and before the remove icon. | 4px |
| --ads-select-tag-padding-start | Padding of a tag at the start, and at both ends of the collapsed tag. | 8px |
| --ads-select-tag-padding-end | Padding of a tag at the end, after the remove icon. | 4px |
| --ads-select-tag-remove-size | Size of the remove icon of a tag. | 10px |
| --ads-select-tag-bg | Background of a tag. | rgba(0, 0, 0, 0.06) |
| --ads-select-tag-border | Border color of a tag (it shows in forced-colors modes). | transparent |
| --ads-select-tag-color-disabled | Text color of a tag that cannot be removed. | rgba(0, 0, 0, 0.25) |
| --ads-select-popup-padding | Padding of the panel around the list. | 4px |
| --ads-select-popup-radius | Corner radius of the panel. | 8px |
| --ads-select-popup-bg | Background of the panel. | #ffffff |
| --ads-select-popup-shadow | Shadow of the panel. | 0 6px 16px 0 rgba(0, 0, 0, 0.08), 0 3px 6px -4px rgba(0, 0, 0, 0.12), 0 9px 28px 8px rgba(0, 0, 0, 0.05) |
| --ads-select-option-radius | Corner radius of an option. | 4px |
| --ads-select-option-height | Least height of an option. | 32px |
| --ads-select-option-font-size | Font size of the list. | 14px |
| --ads-select-option-line-height | Line height of the list. | 1.5714285714285714 |
| --ads-select-option-padding-block | Vertical padding of an option. | 5px |
| --ads-select-option-padding-inline | Horizontal padding of an option and of a group label. | 12px |
| --ads-select-option-gap | Distance between the options. | 2px |
| --ads-select-option-active-bg | Background of the highlighted option. | rgba(0, 0, 0, 0.04) |
| --ads-select-option-selected-bg | Background of a selected option. | #e6f4ff |
| --ads-select-option-selected-color | Text color of a selected option. | rgba(0, 0, 0, 0.88) |
| --ads-select-selected-font-weight | Font weight of a selected option. | 600 |
| --ads-select-group-font-size | Font size of a group label. | 12px |
| --ads-select-group-label-color | Text color of a group label (the accessible file darkens it). | rgba(0, 0, 0, 0.45) |
| --ads-select-empty-color | Text color of the empty-result text (the accessible file darkens it). | rgba(0, 0, 0, 0.45) |
Accessibility
- The focused element has
role="combobox"witharia-expanded,aria-controlsandaria-activedescendant; the list is alistboxofoptions andgroups. DOM focus never leaves the field: the highlighted option is shown byaria-activedescendant. - A name is required:
<label for>,aria-labeloraria-labelledby. The placeholder is not a name. The list takes the name of the field. - Keys: Down, Up, Alt+Down and Alt+Up, Enter and Space, Home and End, PageUp and PageDown, Escape, Tab and Backspace. A field that cannot search also finds an option by typing the start of its text. Tab only closes the list and keeps the value.
- Selected options have
aria-selected="true", disabled onesaria-disabled. While searching, a polite status line says how many options match, or the empty-result text when nothing does. - The clear and remove buttons are native buttons named
ClearandRemove …; they do not take focus from the field. The icons are hidden from assistive technology. Forced-colors modes (Windows High Contrast) are supported. - The default light colors are Ant Design's own and do not reach WCAG AA for every text; import
tokens-accessible.cssfor colors that do. The dark theme keeps AA without it. - Support for
aria-activedescendantin iOS VoiceOver has been weak, so check a Select by hand on that platform before you rely on it. - Known limitation: Orca announces a change of
aria-selectedonly after the Space key. In a field that searches (the default ofmultipleandtags) Space types a space and Enter toggles an option, so Orca says nothing then; the field reads the selected values when it gets focus. Orca also says no values of a field with several values that does not search (showSearch={false}). NVDA, JAWS and VoiceOver have not been tried yet. An announcement of the toggled option is planned for v1.1, together with the translation of the built-in texts.