Combobox
A text input that filters a list of options as you type, for picking one value from a long list.
<arc-combobox>Overview
Combobox is a text input over a list of <arc-option> elements. Typing narrows the list to options whose text contains the query, ignoring case. Picking an option, by click or by Enter on the highlighted one, closes the list, puts the option's text in the input and fires arc-change with its value. Every keystroke fires arc-input with the query.
Use it when the list is too long to scroll through but the value has to be one of the options, such as a country field. There's no free-text entry.
Each <arc-option> needs a value, and its text content is the label that's shown and searched. The component renders its own copy of each option and hides the ones you wrote.
Guidelines
Do
- Give every option a distinct `value`. Selection is tracked by value
- Write a placeholder that says the field is searchable, such as "Search countries..."
- Set `label`. It renders above the input and is the accessible name
Don't
- Don't use it for a handful of options. A Select is quicker
- Don't put anything but `<arc-option>` in the slot. Other elements are ignored
Features
- The input has `role="combobox"` with `aria-expanded`, `aria-controls` and `aria-activedescendant`, and the list is a `listbox` of `option` elements
- Arrow Down and Arrow Up move the highlight, Enter selects and Escape closes. Home and End move the highlight only while the input is empty
- Disabled options are dimmed, skipped by the arrow keys and can't be selected
- Shows "No results found" when nothing matches the query
- Clicking outside or moving focus away closes the list
- Form-associated: give it a `name` and the selected value submits with the form
- `readonly` blocks typing and selection, but the input stays focusable, the list still opens and the value still submits
Preview
Usage
This component needs JavaScript. Use the Web Component or a framework wrapper.
<arc-combobox label="Select Fruit" placeholder="Type to search...">
<arc-option value="apple">Apple</arc-option>
<arc-option value="banana">Banana</arc-option>
<arc-option value="cherry">Cherry</arc-option>
</arc-combobox>import { Combobox, Option } from '@arclux/arc-ui-react';
export default function Example() {
return (
<Combobox label="Select Fruit" placeholder="Type to search...">
<Option value="apple">Apple</Option>
<Option value="banana">Banana</Option>
<Option value="cherry">Cherry</Option>
</Combobox>
);
}<script setup>
import { Combobox, Option } from '@arclux/arc-ui-vue';
</script>
<template>
<Combobox label="Select Fruit" placeholder="Type to search...">
<Option value="apple">Apple</Option>
<Option value="banana">Banana</Option>
<Option value="cherry">Cherry</Option>
</Combobox>
</template><script>
import { Combobox, Option } from '@arclux/arc-ui-svelte';
</script>
<Combobox label="Select Fruit" placeholder="Type to search...">
<Option value="apple">Apple</Option>
<Option value="banana">Banana</Option>
<Option value="cherry">Cherry</Option>
</Combobox>import { Component } from '@angular/core';
import { Combobox, Option } from '@arclux/arc-ui-angular';
@Component({
imports: [Combobox, Option],
template: `
<arc-combobox label="Select Fruit" placeholder="Type to search...">
<arc-option value="apple">Apple</arc-option>
<arc-option value="banana">Banana</arc-option>
<arc-option value="cherry">Cherry</arc-option>
</arc-combobox>
`,
})
export class MyComponent {}import { Combobox, Option } from '@arclux/arc-ui-solid';
export default function Example() {
return (
<Combobox label="Select Fruit" placeholder="Type to search...">
<Option value="apple">Apple</Option>
<Option value="banana">Banana</Option>
<Option value="cherry">Cherry</Option>
</Combobox>
);
}import { Combobox, Option } from '@arclux/arc-ui-preact';
export default function Example() {
return (
<Combobox label="Select Fruit" placeholder="Type to search...">
<Option value="apple">Apple</Option>
<Option value="banana">Banana</Option>
<Option value="cherry">Cherry</Option>
</Combobox>
);
}API
valuestring''- The currently selected option value. Reflected as an attribute so it can be read from the DOM. Updated automatically when the user selects an option.
placeholderstring''- Placeholder text shown in the input when no value is entered.
labelstring''- Visible label rendered above the input. Also used as the accessible label for the combobox.
namestring''disabledbooleanfalse- Disables the input and prevents interaction. The host element receives reduced opacity and pointer-events: none.
readonlybooleanfalse- Prevents typing and selecting an option while the input stays focusable; the list can still be opened for viewing and the value still submits.
size'sm' | 'md' | 'lg''md'- Control size.
mdis the default;smandlgscale the field padding. formAssociatedbooleantruepropertiesobject{ // flag(), unlike `disabled`. The exclusion in props.js is specifically // about form-associated *platform* semantics: a `disabled` content // attribute that is merely present makes the element actually disabled // per the HTML spec, and formDisabledCallback assigns the property back, // so no converter can win. Neither of these is platform-mapped: // `required` is enforced by _computeValidity() below and `readonly` by // each component's own interaction handlers, so the stock converter buys // nothing here and costs the usual bug: `required="false"` read as true, // blocking submission of a form the author meant to leave optional. // Finding #48's shape, across all 26 form controls at once. required: flag(false), readonly: flag(false), }- Lit merges static properties up the prototype chain, so every consumer
gets these without declaring them.
requiredparticipates in constraint validation below;readonlyreflects for styling and is enforced by each component's interaction handlers (the mixin can't know which gestures mutate state). autoValidatesbooleantrue- Components that run their own constraint-validation logic (pattern checks, range checks) opt out of the automatic required sync by overriding this to false, and own the whole validity flag set instead.
formvalidityvalidationMessagerequiredbooleanfalse
Methods
checkValidity()boolean- Whether the control currently satisfies its constraints, per the native
constraint-validation API. Fires
invalidon the element when it does not, and reports nothing to the user. reportValidity()boolean- As checkValidity(), but also shows the browser's validation message against the control when it fails.
Events
arc-input- Fired on every keystroke in the filter input.
event.detail.valuecontains the current query text. arc-change- Fired when an option is selected.
event.detail.valuecontains the selected option value.
See also
- SelectA dropdown for choosing one option from a list in a form.
- Multi SelectA dropdown for picking several options, shown as removable chips.
- SearchA search field with an optional dropdown of suggestions that you supply.
- Command PaletteCommand list that opens as a dialog, with fuzzy, ranked search and shortcut hints.