combo-box

Autocomplete combobox with filtering, keyboard navigation, and native form association. Supports single-select and multi-select tag modes.

Overview

An autocomplete combobox following the W3C ARIA combobox pattern. Users type to filter a list of options, navigate with arrow keys, and select with Enter or click. The selected value participates in native form submission via ElementInternals.

Add multiple to enable multi-select tag mode, where users can select multiple items as tag chips.

Usage

Place an <input> and a <ul> inside <combo-box>. Each <li> needs a data-value attribute for the form value. The visible text content becomes the label.

Inside a Form

Use the standard name attribute to set the form field name. The selected value is submitted as the form value. Add required to enable required validation.

Filter Modes

By default, typing filters options by substring match (contains). Set filter="startsWith" to only match from the beginning of each option.

Multi-Select Mode

Add multiple to switch to multi-select tag mode. Users select multiple items which appear as removable tag chips. Selected options are hidden from the dropdown to prevent duplicates.

Multi-Select Options

In multi mode, use max to limit the number of selections and custom to let users type custom entries (press Enter or comma to add). Each selected tag is submitted as a separate FormData entry (like multiple checkboxes with the same name).

Attributes

AttributeValuesDefaultDescription
namestringForm field name
requiredbooleanRequire a selection for form validation
filter"contains", "startsWith"containsHow typing filters the options
valuestringSelected value (single mode)
placeholderstringInput placeholder text
multiplebooleanEnable multi-select tag mode
maxnumberMaximum number of tags (multi mode)
custombooleanAllow typed entries via Enter/comma (multi mode)

Required Structure

ElementRequiredDescription
<input type="text">yesText input for filtering and display
<ul> or <ol>yesOptions list container
<li data-value>yesIndividual option — one per selectable choice

Child Attributes

AttributeOnValuesDescription
data-valuelistringOption value identifier placed on each <li> in the options list

Events

EventDetailDescription
combo-box:change{ value, label }Fired when an option is selected (single mode).
combo-box:change{ values: string[], labels: string[] }Fired when tags are added or removed (multi mode).
combo-box:openFired when the listbox opens.
combo-box:closeFired when the listbox closes.

Single Mode

Multi Mode

JavaScript API

PropertyTypeModeDescription
element.valuestringSingleCurrent selected value (read/write)
element.labelstringSingleCurrent selected label (read-only)
element.valuesstring[]MultiArray of selected tag values (read-only)
element.labelsstring[]MultiArray of selected tag labels (read-only)

Single Mode

Multi Mode

Progressive Enhancement

Without JavaScript, <combo-box> renders as a plain text input above a visible, scrollable list. Users can still see all options and type into the input. Once JS loads, the component adds filtering, keyboard navigation, and form association.

Related