Skip to content

HyCombobox

Usage examples on this page are written for Lit / plain HTML (<hy-combobox>). The same component ships as HyCombobox in @whitespaceux/harmony-react (native React 19), with typed wrappers for Angular, Solid, Svelte, and Vue. The API reference below applies to all frameworks.

A combobox — a filterable single-select that combines a text input with a listbox popup. Follows the WAI-ARIA APG combobox pattern: DOM focus stays on the input, option highlight moves via aria-activedescendant.

The listbox is positioned with Floating UI: offset + flip + shift keep the popup inside the viewport near the input, and the size middleware caps the listbox height to the available space so long lists remain scrollable instead of spilling off-screen. autoUpdate repositions on scroll/resize while the listbox is open.

Alpha scope: single-select, client-side filtering, no creatable free text, no virtualization. Multi-select ships as a sibling hy-multi-combobox; creatable values are deferred.

Options are passed as a property (.options = [...]). The value property is the currently committed option value (or null). Filtering is controlled internally via filterOption; return false for every option to disable client filtering and drive options server-side.

Accessible name. Provide one of: the label property (visible label above the control), aria-label on the host (when the surrounding context already names it), or aria-labelledby referencing another element's id. The dev-mode WCAG 1.3.1 warning fires only when none of the three is set; aria-label / aria-labelledby on the host are forwarded to the inner <input> so screen readers see them.

Examples

javascript
<hy-combobox label="Country" placeholder="Search countries"></hy-combobox>
<script>
  const box = document.querySelector('hy-combobox');
  box.options = [
    { value: 'ch', label: 'Switzerland' },
    { value: 'fr', label: 'France' },
    { value: 'de', label: 'Germany' },
  ];
  box.addEventListener('change', (e) => console.log(e.detail.value));
</script>

API

Properties

PropertyAttributeTypeDefaultDescription
optionsComboboxOption[][]Option list. Property-only — arrays are not reflectable.
valuevaluestring | nullnullCommitted value. null when nothing is selected.
labellabelstring''Visible label above the input.
helperTexthelper-textstring''Helper text below the input. Hidden when errorMessage is shown.
errorMessageerror-messagestring''Error message — shown below the input when invalid.
placeholderplaceholderstring''Placeholder shown when the input is empty.
sizesize'small' | 'medium' | 'large''medium'Input size — matches sibling form controls.
layoutlayout'block' | 'inline''block'Row layout: block (default) stacks label above the combobox; inline puts label on the left and combobox on the right. Helper/error always sit under the control (col 2–end), never under the label. Set --hy-combobox-label-column-width on a wrapping container so stacked comboboxes align.
widthwidthstring | undefinedWidth of the combobox container. Accepts any valid CSS width value (e.g. '400px', '100%', '20rem'). The host fills its container by default; set width to constrain the field. Mirrors hy-text-input.
namenamestring''Form name — surfaces the selected value to FormData.
disableddisabledbooleanfalseDisables the control.
requiredrequiredbooleanfalseMarks the field as required for form validation.
invalidinvalidbooleanfalseVisually marks the field as invalid.
clearableclearablebooleantrueWhether to show a clear-button when a value is set.
clearLabelclear-labelstring'Clear selection'Accessible name of the clear button.
emptyTextempty-textstring'No results'Fallback text when no options match the current query.
openopenbooleanfalseControlled open state. Leave unset for uncontrolled behavior.
autofocusautofocusbooleanfalseMarks this combobox as the auto-focus target. Read by hy-dialog (and other overlay containers) on show to choose initial focus. Also focuses on first connect when used outside an overlay, mirroring native HTML autofocus but routed through JS so SSR'd HTML doesn't pull focus during hydration.
autoselectautoselectbooleanfalseAfter auto-focus lands, selects the current value so the user can type-to-replace. Pairs with autofocus for rename-style dialogs where the existing value is shown for context but is meant to be overwritten.
filterOptionComboboxFilterdefaultFilterCustom filter. Called for each option; return true to include. Default is a case-insensitive substring match on label.
formHTMLFormElement | null
validityValidityState
validationMessagestring

Events

EventDetailDescription
changeFires when the selected value commits. Detail: ComboboxChangeDetail.
inputFires while the user types. Detail: ComboboxInputDetail.
showFires when the listbox opens (does NOT bubble). Detail: HyVisibilityDetail.
hideFires when the listbox closes (does NOT bubble). Detail: HyVisibilityDetail.

CSS Parts

PartDescription
baseOuter wrapper containing label, control, helper/error.
labelThe <label> element.
containerThe input + trailing icons container.
inputThe text <input>.
clear-buttonThe clear affordance (visible when clearable and a value is set).
expand-iconThe chevron indicating popup state.
listboxThe popup <ul role="listbox">.
optionAn individual <li role="option">.
emptyThe no-results message container.
helper-textHelper text below the input.
error-messageError message below the input.

CSS Custom Properties

PropertyDescription
--hy-combobox-listbox-max-heightMaximum height of the popup before scrolling. Overridden at runtime by Floating UI's size middleware when viewport space is tighter.
--hy-combobox-label-column-widthWidth of the label column in layout="inline" mode. No default — set on a wrapping container so stacked comboboxes align.
--hy-combobox-height-smOuter height for small size variant. Per-component override in the form-control height contract (see .claude/rules/control-heights.md). Default: var(--hy-control-height-sm)
--hy-combobox-height-mdOuter height for medium size variant. Default: var(--hy-control-height-md)
--hy-combobox-height-lgOuter height for large size variant. Default: var(--hy-control-height-lg)
--hy-combobox-hover-durationTransition duration for hover and focus state feedback
--hy-combobox-hover-easingTransition easing for hover and focus state feedback
--hy-combobox-expand-durationTransition duration for the listbox expand and collapse animation
--hy-combobox-expand-easingTransition easing for the listbox expand and collapse animation

Methods

select()

Selects all text in the combobox's underlying input.

Built with Lit. Documented with VitePress.