The Select component provides an enhanced dropdown selection interface with search, multi-select, and option creation. Built on Svelecte with TypeScript support.
For validated forms, use FormSelect inside a parent Form. FormSelect requires Form context.
Setup
<script>
import { Select } from '.';
</script> Usage
<script>
import { Select } from '.';
let selectedValue = $state('');
const options = [
{ value: 'apple', label: 'Apple' },
{ value: 'banana', label: 'Banana' },
{ value: 'cherry', label: 'Cherry' }
];
</script>
<Select bind:value={selectedValue} {options} placeholder="Select a fruit" /> Multi-select
<script>
import { Select } from '.';
</script>
<Select
multiple
options={[
{ value: 'react', label: 'React' },
{ value: 'svelte', label: 'Svelte' },
{ value: 'vue', label: 'Vue' }
]}
/> Creatable
<script>
import { Select } from '.';
</script>
<Select creatable placeholder="Add tags..." /> Disabled
<script>
import { Select } from '.';
const options = [
{ value: 'apple', label: 'Apple' },
{ value: 'banana', label: 'Banana' }
];
</script>
<Select disabled {options} /> Object values
<script>
import { Select } from '.';
</script>
<Select
valueAsObject
options={[
{ id: 1, name: 'John', email: 'john@example.com' },
{ id: 2, name: 'Jane', email: 'jane@example.com' }
]}
valueField="id"
labelField="name"
/> Events
Prefer onchange. onChange is deprecated.
<script>
import { Select } from '.';
const options = [
{ value: 'us', label: 'United States' },
{ value: 'ca', label: 'Canada' }
];
</script>
<Select {options} onchange={(e) => console.log('Selected:', e)} /> Accessibility
- Keyboard navigation, ARIA attributes, and focus management via Svelecte.
- Set
inputIdand pair with aLabelforattribute. - Use
required/disabledfor native semantics; surface validation with Form context helpers.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
options | Array | object | — | Selectable options |
value | any | any[] | null | — | Bindable selection |
placeholder | string | — | Empty-state text |
name | string | — | Form field name |
inputId | string | — | Underlying input id |
required / disabled | boolean | false | Native constraints |
multiple | boolean | false | Multi-select |
searchable | boolean | — | Filter options |
clearable | boolean | — | Clear selection control |
creatable | boolean | false | Allow creating options |
valueAsObject | boolean | false | Return full option objects |
labelAsValue | boolean | false | Use label when value missing |
hasError / hasSuccess | boolean | — | Visual validation state |
minHeight | number | — | Control min height |
valueField / labelField | string | null | — | Option field mapping |
groupLabelField / groupItemsField | string | — | Grouped options |
disabledField | string | — | Per-option disabled key |
renderer | fn | string | — | Custom option render |
disableHighlight | boolean | — | Disable search highlight |
highlightFirstItem | boolean | — | Highlight first match |
selectOnTab | boolean | 'select-navigate' | — | Tab selection behavior |
resetOnBlur / resetOnSelect | boolean | — | Reset input text |
closeAfterSelect | boolean | string | — | Close dropdown after select |
deselectMode | native | toggle | none | — | Deselect behavior |
max | number | — | Max selections (multi) |
collapseSelection | blur | always | null | — | Collapse multi chips |
keepSelectionInList | boolean | auto | — | Keep selected in list |
creatablePrefix | string | — | Prefix for created items |
allowEditing / keepCreated | boolean | — | Creatable editing |
delimiter | string | — | Multi-value delimiter |
createFilter / createHandler | functions | — | Creatable hooks |
fetch / fetchProps / fetchMode | remote API | — | Async options |
fetchCallback / fetchResetOnBlur / fetchDebounceTime | fetch helpers | — | Remote fetch tuning |
minQuery | number | — | Min chars before fetch |
lazyDropdown / virtualList / vlItemSize | list perf | — | Virtualization |
i18n | object | — | Locale strings |
readSelection | object | object[] | null | — | External selection mirror |
parentValue | string | number | null | — | Cascading parent value |
emitValues | boolean | — | Emit raw values |
loading | boolean | — | Loading indicator |
onchange | Function | — | Selection change |
onChange | Function | — | Deprecated; prefer onchange |
onFocus / onBlur | Function | — | Focus events |
onCreateOption / onCreateFail | Function | — | Creatable events |
onEnterKey | Function | — | Enter key |
onFetch / onFetchError | Function | — | Remote fetch events |
onInvalidValue | Function | — | Invalid value handler |
prepend / append | Snippet | — | Control adornments |
selection / clearIcon / toggleIcon | Snippet | — | Custom chrome |
listHeader / option | Snippet | — | List customization |
controlClass / dropdownClass / optionClass | string | null | — | Style hooks |
class | ClassValue | — | Root classes |
positionResolver / anchor_element / dndzone / strictMode | advanced | — | Positioning / DnD |
FormSelect
FormSelect extends SelectProps with required name, optional label and contextKey. Must be a child of Form.