Combobox <l-combobox>
A text input paired with a filterable list of options — type to narrow the list, then pick a match.
<l-combobox><l-combobox
label="Country"
name="country"
placeholder="Search a country…"
>
<datalist>
<option value="us">United States</option>
<option value="fr">France</option>
<option value="de">Germany</option>
</datalist>
</l-combobox>Options are authored as a native <datalist> of <option> — the same authoring surface as <select>.
Options
Basic
Author the choices as <option> inside a <datalist>. label names the input; name submits the chosen value.
Code
<div class="w-72">
<l-combobox
label="Country"
name="country"
placeholder="Search a country…"
>
<datalist>
<option value="us">United States</option>
<option value="fr">France</option>
<option value="de">Germany</option>
<option value="es">Spain</option>
<option value="it">Italy</option>
<option value="jp">Japan</option>
</datalist>
</l-combobox>
</div>Clearable
Add with-clear for a button that resets the value.
Code
<div class="w-72">
<l-combobox
label="Country"
value="fr"
with-clear
>
<datalist>
<option value="us">United States</option>
<option value="fr">France</option>
<option value="de">Germany</option>
<option value="es">Spain</option>
</datalist>
</l-combobox>
</div>Taller controls
The clear button and the chevron each take a square as tall as the field, borders excluded: their hit area and the space between them grow with the control. Set --height on the element, or --l-form-control-height on an ancestor to resize every form control at once. The glyphs keep their size; resize them with --l-form-control-icon-size (default 1em).
Code
<div class="w-72">
<l-combobox
label="Country"
value="fr"
with-clear
class="[--height:42px]"
>
<datalist>
<option value="us">United States</option>
<option value="fr">France</option>
<option value="de">Germany</option>
<option value="es">Spain</option>
</datalist>
</l-combobox>
</div>Custom values
Add allow-custom to accept a typed value that matches no option.
Code
<div class="w-72">
<l-combobox
label="Tag"
placeholder="Pick or type a tag…"
allow-custom
>
<datalist>
<option value="bug">Bug</option>
<option value="feature">Feature</option>
<option value="docs">Documentation</option>
</datalist>
</l-combobox>
</div>Rich options
Put markup inside each <option> — the same .l-select-item-media / .l-select-item-text / .l-select-item-title / .l-select-item-description classes as <select>. Set a label (or .l-select-item-title) so filtering and the input display use the title.
As you type, the match is highlighted inside .l-select-item-title and .l-select-item-description, with the same accent/case-insensitive matching as plain options. Only the text is wrapped in <mark>; the option's markup is kept as authored.
Code
<div class="w-72">
<l-combobox
label="Country"
placeholder="Search a country…"
>
<datalist>
<option
value="us"
label="United States"
>
<span class="l-select-item-media"><l-icon name="circle-flags:us"></l-icon></span>
<span class="l-select-item-text">
<span class="l-select-item-title">United States</span>
<span class="l-select-item-description">North America</span>
</span>
</option>
<option
value="fr"
label="France"
>
<span class="l-select-item-media"><l-icon name="circle-flags:fr"></l-icon></span>
<span class="l-select-item-text">
<span class="l-select-item-title">France</span>
<span class="l-select-item-description">Europe</span>
</span>
</option>
<option
value="jp"
label="Japan"
>
<span class="l-select-item-media"><l-icon name="circle-flags:jp"></l-icon></span>
<span class="l-select-item-text">
<span class="l-select-item-title">Japan</span>
<span class="l-select-item-description">Asia</span>
</span>
</option>
</datalist>
</l-combobox>
</div>Suffix
Add a .l-select-item-suffix after .l-select-item-text to pin a badge, a count or a status icon to the end of the row, before the checkmark. It sits on the title's line, keeps its natural width while the title truncates, and is never matched by the filter or written into the input. Rich options are copied into the popover's shadow root: an <l-badge> is styled there, but your page's own selectors don't reach that copy. To theme it, set the badge's CSS custom properties on the <l-combobox>: they inherit into the popover. Screen readers announce the suffix with its option, so write it as words ("12 members", not "12").
Code
<div class="w-80">
<l-combobox
label="Team"
placeholder="Search a team…"
>
<datalist>
<option
value="design"
label="Design"
>
<span class="l-select-item-text">
<span class="l-select-item-title">Design</span>
<span class="l-select-item-description">Product and brand design</span>
</span>
<span class="l-select-item-suffix">
<l-badge
size="sm"
appearance="filled"
>12 members</l-badge
>
</span>
</option>
<option
value="engineering"
label="Engineering"
>
<span class="l-select-item-text">
<span class="l-select-item-title">Engineering</span>
<span class="l-select-item-description">Platform, web and mobile apps</span>
</span>
<span class="l-select-item-suffix">
<l-badge
size="sm"
appearance="filled"
>48 members</l-badge
>
</span>
</option>
<option
value="support"
label="Support"
>
<span class="l-select-item-text">
<span class="l-select-item-title">Support</span>
<span class="l-select-item-description">Customer success and onboarding</span>
</span>
<span class="l-select-item-suffix">
<l-badge
size="sm"
appearance="filled"
variant="warning"
>Full</l-badge
>
</span>
</option>
</datalist>
</l-combobox>
</div>Disabled
Native disabled attribute.
Code
<div class="w-72">
<l-combobox
label="Country"
value="fr"
disabled
>
<datalist>
<option value="fr">France</option>
<option value="de">Germany</option>
</datalist>
</l-combobox>
</div>Custom filter
By default options are matched case- and accent-insensitively (every space-separated keyword must appear). Override the filter property — (item, query) => boolean — for startsWith, fuzzy, or remote-driven filtering.
The default filter only reads the label (a rich option's title). To search the description too, match against the text of item.html — the match is then highlighted in the description as well. Try a capital or a continent:
Code
<div class="w-72">
<l-combobox
id="demo-combobox-filter"
label="Country"
placeholder="Search a country or capital…"
>
<datalist>
<option
value="fr"
label="France"
>
<span class="l-select-item-text">
<span class="l-select-item-title">France</span>
<span class="l-select-item-description">Capital: Paris · Europe</span>
</span>
</option>
<option
value="jp"
label="Japan"
>
<span class="l-select-item-text">
<span class="l-select-item-title">Japan</span>
<span class="l-select-item-description">Capital: Tokyo · Asia</span>
</span>
</option>
<option
value="br"
label="Brazil"
>
<span class="l-select-item-text">
<span class="l-select-item-title">Brazil</span>
<span class="l-select-item-description">Capital: Brasília · South America</span>
</span>
</option>
<option
value="ke"
label="Kenya"
>
<span class="l-select-item-text">
<span class="l-select-item-title">Kenya</span>
<span class="l-select-item-description">Capital: Nairobi · Africa</span>
</span>
</option>
</datalist>
</l-combobox>
</div>const combobox = document.querySelector('l-combobox');
// `item.html` is the rich option's markup: compare against its text, not its tags.
const textOf = (html) => {
const template = document.createElement('template');
template.innerHTML = html;
return template.content.textContent;
};
combobox.filter = (item, query) =>
`${item.label} ${item.html ? textOf(item.html) : ''}`
.toLowerCase()
.includes(query.trim().toLowerCase());Match highlight
The part of each option that matches the query is wrapped in <mark>. Theme it with two form-control tokens, or set the highlight property to false to turn it off.
:root {
--l-form-control-match-background-color: transparent;
--l-form-control-match-font-weight: var(--l-font-weight-bold);
}Dynamic options
The <datalist> is watched: re-labelling, adding, removing, or disabling an <option> after mount updates the input and the listbox immediately — no reopen, no remount. Text the user is typing is left alone.
const option = document.querySelector('l-combobox option[value="fr"]');
// The input re-renders on its own — nothing to call, nothing to remount.
option.label = 'Français';Accessibility
Criteria
Rules
- Always set
labelso the input has an accessible name
Keyboard interactions
API reference
Importing
import 'luxen-ui/combobox';Attributes & Properties
valuestringProperty- Selected value (the chosen option's
value). placeholderstringProperty- Placeholder text in the input.
labelstringProperty- Accessible label for the input.
sizeComboboxSizedefault:'md'Property- Control size.
with-clearbooleandefault:falseProperty- Show a button to clear the value.
allow-custombooleandefault:falseProperty- Accept a typed value that matches no option.
highlightbooleandefault:trueProperty- Wrap the matching substring of each option in
<mark>— the label of a plain option, the title and description of a rich one. placementPlacementdefault:'bottom-start'Property- Panel placement relative to the control.
filterComboboxFilterdefault:defaultFilterProperty- Override the option filter.
(item, query) => boolean.
Events
changeEvent- Fired when an option is selected. Bubbles. Not cancelable. Properties:
value: string. inputEvent- Fired as the user types. Bubbles. Not cancelable. Properties:
value: string(the query). showcancelableEvent- Fired before the list opens. Cancelable.
hidecancelableEvent- Fired before the list closes. Cancelable.
CSS parts
basePart- The host wrapper.
controlPart- The input control row (input + clear + chevron).
inputPart- The text input.
panelPart- The floating popover panel.
listboxPart- The options container.
optionPart- Each option row.
emptyPart- The "no results" message.
CSS classes
.l-select-item-mediaClass- Rich option: leading image or icon.
.l-select-item-textClass- Rich option: column holding the title and the description.
.l-select-item-titleClass- Rich option: title, truncated with an ellipsis. Used as the label when the option has no
label. .l-select-item-descriptionClass- Rich option: secondary line, shown in the listbox only.
.l-select-item-suffixClass- Rich option: trailing badge, count or status icon on the title's line. Kept out of the input and the filter.
CSS custom properties
--heightdefault:var(--l-form-control-height)Custom property- Control height. The clear button and the chevron each take a square of this height (borders excluded), so their hit area and spacing follow it.
--l-form-control-icon-sizedefault:1emCustom property- Glyph size of the clear button and the chevron (global form-control token; set it here or on any ancestor). Changes the glyph only — the hit area follows
--height. --chevron-iconCustom property- Chevron glyph as a
url(). Masked, so its color comes from the control, not the image. --clear-iconCustom property- Clear button glyph as a
url(). --border-radiusCustom property- Control + panel radius.
--backgroundCustom property- Panel background.