KANTO DS v1.12.0
Customise

Theme

Accent

Font

Corners

Density

Text size

Reset to Kanto
Forms

kt-input-menu

GitHub Copy link

A combobox: type to narrow the list, then pick.

Preview

A combobox: type to narrow the list, then pick.

<kt-input-menu placeholder="Search a country"></kt-input-menu>menu.options = [ { id: 'fr', label: 'France' }, { id: 'be', label: 'Belgium' }, { id: 'ch', label: 'Switzerland' }, ]; menu.addEventListener('kt-change', (e) => console.log(e.detail.value)); menu.addEventListener('kt-filter', (e) => console.log(e.detail.query));

Against <kt-select>

Both choose one option from a list. Reach for the combobox once scanning the list is slower than typing three letters — roughly twenty options. Below that, <kt-select> is less work for the user: no typing, and the whole list is visible.

One field, two jobs

While the list is open and a query has been typed, the field shows the query. Otherwise it shows the chosen option's label. That single field is what makes this a combobox rather than a search box that happens to sit above a list.

Escape closes and forgets the query, leaving the previous selection intact.

Server-side filtering

kt-filter fires on every keystroke, so a large or remote list can be fetched instead of filtered locally — assign the results back to options and the element renders them.

menu.addEventListener('kt-filter', async (e) => { menu.options = await search(e.detail.query); });

In a form

<kt-input-menu> is a form control. Inside a <form> it submits the chosen option's id under name — never the label, and nothing at all while empty. required blocks submission until something is chosen, and form.reset() puts back the initial value.

Keyboard

KeyDoes
↓ / ↑Opens the list, then moves the active option
Home / EndFirst / last match
EnterCommits the active option
EscapeCloses, forgets the query, keeps the selection
TabCloses and moves on

The arrows walk the filtered list, not the full one.

API

PropertyAttributeTypeDefault
options—KtOption[][]
valuevaluestring | number | nullnull
placeholderplaceholderstring''
namenamestring''
disableddisabledbooleanfalse
requiredrequiredbooleanfalse
errorerrorstring''
labellabelstring''
emptyTextempty-textstring'No options…'
EventDetail
kt-change{ value, option }
kt-filter{ query: string }
PartDescription
controlThe field
inputThe native <input>
popupThe option list
optionAn option row