Combobox
A searchable single-select field. The user types to filter options; selecting one sets the value. Keyboard
navigation (Arrow, Enter, Escape) is fully supported. Use lt-select when no filtering is needed.
Each option may also include an optional group (groups a contiguous run of options under one
heading, like a native <optgroup>), icon, and description.
Set the creatable property to let the user create a new option from free text that matches
nothing in the list.
Playground
Usage
<lt-combobox
id="country-picker"
label="Country"
placeholder="Search countries…"
required></lt-combobox>
<script type="module">
const cb = document.getElementById('country-picker');
cb.options = [
{ value: 'us', label: 'United States' },
{ value: 'ca', label: 'Canada' },
{ value: 'gb', label: 'United Kingdom' },
{ value: 'de', label: 'Germany' },
{ value: 'fr', label: 'France' }
];
cb.addEventListener('change', (e) => {
console.log('selected', e.detail.value, e.detail.label);
});
</script>
<!-- Multiple selection: value is an array of the selected values, rendered as removable tags -->
<lt-combobox id="skills" label="Skills" multiple></lt-combobox>
<!-- clearable: shows a clear button once a value is selected -->
<lt-combobox id="clearable-country" label="Country" clearable></lt-combobox>
<!-- loading: shows a spinner in place of the option list, for options fetched as the user types -->
<lt-combobox id="loading-country" label="Country" loading></lt-combobox>
<!-- Option groups, descriptions, and icons: options sharing a "group" render under one heading (consecutive
entries only, like a native <optgroup>); "description" and "icon" are both optional, per option -->
<lt-combobox id="grouped-country" label="Country"></lt-combobox>
<script type="module">
document.getElementById('grouped-country').options = [
{ value: 'us', label: 'United States', group: 'Americas', icon: 'globe' },
{ value: 'ca', label: 'Canada', group: 'Americas' },
{ value: 'gb', label: 'United Kingdom', group: 'Europe' },
{ value: 'fr', label: 'France', group: 'Europe', description: 'Eiffel Tower, croissants' }
];
</script>
<!-- creatable: lets the user create a new option from free text that matches nothing in the list — fires
"create" with the typed text and sets it as the value, but does not modify options itself -->
<lt-combobox id="creatable-tags" label="Skills" multiple creatable></lt-combobox>
<script type="module">
const creatableTags = document.getElementById('creatable-tags');
creatableTags.options = [
{ value: 'js', label: 'JavaScript' },
{ value: 'ts', label: 'TypeScript' }
];
creatableTags.addEventListener('create', (e) => {
console.log('created', e.detail.value);
});
</script>
import { Combobox } from '@latty-ds/react';
const countries = [
{ value: 'us', label: 'United States' },
{ value: 'ca', label: 'Canada' },
{ value: 'gb', label: 'United Kingdom' }
];
<Combobox
label="Country"
placeholder="Search countries…"
options={countries}
onChange={(e) => console.log(e.detail.value)}
required
/>
// Multiple selection: value is an array of the selected values, rendered as removable tags
<Combobox label="Skills" options={skills} multiple />
// clearable: shows a clear button once a value is selected
<Combobox label="Country" options={countries} clearable />
// loading: shows a spinner in place of the option list, for options fetched as the user types
<Combobox label="Country" loading />
// Option groups, descriptions, and icons: options sharing a "group" render under one heading
// (consecutive entries only, like a native <optgroup>); "description" and "icon" are both optional
const groupedCountries = [
{ value: 'us', label: 'United States', group: 'Americas', icon: 'globe' },
{ value: 'ca', label: 'Canada', group: 'Americas' },
{ value: 'gb', label: 'United Kingdom', group: 'Europe' },
{ value: 'fr', label: 'France', group: 'Europe', description: 'Eiffel Tower, croissants' }
];
<Combobox label="Country" options={groupedCountries} />
// creatable: lets the user create a new option from free text that matches nothing in the list — fires
// onCreate with the typed text and sets it as the value, but does not modify options itself
const skills = [
{ value: 'js', label: 'JavaScript' },
{ value: 'ts', label: 'TypeScript' }
];
<Combobox label="Skills" options={skills} multiple creatable onCreate={(e) => console.log('created', e.detail.value)} />
<template>
<lt-combobox
label="Country"
placeholder="Search countries…"
:options="countries"
@change="(e) => selected = e.detail.value"
/>
<!-- Multiple selection: value is an array of the selected values, rendered as removable tags -->
<lt-combobox label="Skills" :options="skills" multiple />
<!-- clearable: shows a clear button once a value is selected -->
<lt-combobox label="Country" :options="countries" clearable />
<!-- loading: shows a spinner in place of the option list, for options fetched as the user types -->
<lt-combobox label="Country" loading />
<!-- Option groups, descriptions, and icons: options sharing a "group" render under one heading
(consecutive entries only, like a native <optgroup>); "description" and "icon" are both optional -->
<lt-combobox label="Country" :options="groupedCountries" />
<!-- creatable: lets the user create a new option from free text that matches nothing in the list — fires
"create" with the typed text and sets it as the value, but does not modify options itself -->
<lt-combobox
label="Skills"
:options="skills"
multiple
creatable
@create="(e) => console.log('created', e.detail.value)"
/>
</template>