Vanilla Breeze v0.7.4

Vanilla Breeze v0.7.4 released

0.7.4 gives the Ambient pack weather. A page names one feed URL on its own site, and the pack sets data-weather from it, uses its sunrise and sunset for dawn and dusk, and never shows a stale observation. Helpers for producing the feed from Open-Meteo are included. Ambient p…

Read the release notes

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. Give the input an id and point a <label for> at it: the component keeps the input’s id and labels, so the label names the combobox. A placeholder is not a label.

Inside a Form

Put the name on the inner input. Without JavaScript the plain input submits the typed text under that name. On upgrade the component moves the name to itself (if the host has a name too, the host wins) and removes it from the input, so the form submits exactly one entry: the selected option’s data-value. Add required to enable required validation, and disabled (or a disabled ancestor <fieldset>) to disable the field.

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
namestring—Form field name. A name on the inner input (the no-JS path) moves here on upgrade so exactly one value submits.
requiredboolean—Require a selection for form validation
disabledboolean—Disables the input and tag remove buttons, closes the listbox and drops the value from submission. A disabled ancestor fieldset has the same effect.
filter"contains", "startsWith"containsHow typing filters the options
valuestring—Selected value (single mode)
placeholderstring—Input placeholder text
multipleboolean—Enable multi-select tag mode
maxnumber—Maximum number of tags (multi mode)
customboolean—Allow typed entries via Enter/comma (multi mode)

Required Structure

ElementRequiredDescription
<input type="text">yesText input for filtering and display. Give it an id and point a <label for> at it — the id and labels are preserved and name the combobox.
<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
nameinputstringSubmission name for the no-JS fallback (submits the typed text). Moved to the host on upgrade (the host's own name wins if both are set).

Events

EventDetailDescription
combo-box:change{ value, label, source }Fired when the selected option changes (single mode). Re-choosing the current option closes the list without firing.
combo-box:change{ values: string[], labels: string[], source }Fired when tags are added or removed (multi mode).
combo-box:open—Fired when the listbox opens.
combo-box:close—Fired 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

Keyboard Navigation

KeyAction
ArrowDownOpen listbox / move to next option
ArrowUpOpen listbox / move to previous option
HomeJump to first option
EndJump to last option
EnterSelect option (single) or add tag (multi). With custom: add typed text. With no active option and nothing to add, Enter submits the surrounding form.
EscapeClose listbox
TabClose listbox and move focus
BackspaceRemove last tag when input is empty (multi mode)
, (comma)Add custom tag (multi mode with custom)

Accessibility

ARIA Pattern

Implements the W3C ARIA Combobox pattern:

  • Input has role="combobox", aria-expanded, aria-autocomplete="list", and aria-controls
  • List has role="listbox" with an auto-generated ID
  • Options have role="option" and aria-selected
  • Active option announced via aria-activedescendant
  • Multi mode adds aria-multiselectable="true" and an aria-live region for tag add/remove announcements

Form Validation

Validity is set on the host with ElementInternals.setValidity(), anchored to the inner input, so the browser’s validation bubble points at the input and the host matches :invalid, :user-valid and :user-invalid. The host is not focusable, so validity on it alone is not announced. When the browser reports the field invalid (on submit or checkValidity()), the component sets aria-invalid="true" on the focusable input, and removes it once a valid selection is made or the form is reset. It is deliberately not set on page load, before the user has interacted.

Form Association

This component is a Form-Associated Custom Element. It uses ElementInternals to:

  • Submit the selected value via FormData (single mode: one value; multi mode: one entry per tag)
  • Validate with setValidity() for required fields
  • Reset on form reset via formResetCallback()
  • Restore state from browser history via formStateRestoreCallback() (single mode)

No hidden inputs needed. The name can sit on the host or on the inner input (for the no-JS path); either way exactly one value is submitted after upgrade. A disabled host (attribute or <fieldset disabled>) submits nothing.

Styling

The component uses @scope (combo-box) for shared CSS encapsulation and @scope (combo-box[multiple]) for tag-specific styles. Override option states and tag chip appearance using standard selectors:

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, and a name on the input submits the typed text. Once JS loads, the component adds filtering, keyboard navigation, and form association, and submits the option’s data-value instead.

Related

  • Form-Associated Custom Elements — Guide to the pattern
  • <star-rating> — Another form-associated component
  • <drop-down> — Action menu (non-form)
  • <datalist> — Native autocomplete
  • data-toggle-tags — For a short, fixed set of options that should all stay visible, real checkboxes styled as chips (no JS unless you add data-max). Choose <combo-box multiple> for long or searchable lists and custom entries.
↑