Skip to content
Focsd homeFocsd homeFocsd
Forms

Combobox

A text input that filters a list of options as you type.

  • Tag: focsd-combobox
  • Pattern: Combobox (autocomplete)
  • Category: Forms

Example

Denmark Finland France Germany United Kingdom
HTML
<div class="stack">
<focsd-combobox label="Country" placeholder="Start typing" clearable>
<focsd-option-group label="Nordics">
<focsd-option value="dk">Denmark</focsd-option>
<focsd-option value="fi">Finland</focsd-option>
</focsd-option-group>
<focsd-option-group label="Western Europe">
<focsd-option value="fr">France</focsd-option>
<focsd-option value="de">Germany</focsd-option>
<focsd-option value="gb">United Kingdom</focsd-option>
</focsd-option-group>
</focsd-combobox>
</div>

Usage

Import the module once, then use the tag like any HTML element. Every framework below renders the same element; see Frameworks for setup.

<script type="module">
import '@focsd-dev/components/focsd-combobox.js';
</script>
<focsd-combobox label="Country" placeholder="Start typing" clearable>…</focsd-combobox>

API

Attributes

AttributePropertyTypeDefault
namenamestring—
disableddisabledbooleanfalse
requiredrequiredbooleanfalse
readonlyreadOnlybooleanfalse
aria-labelhostAriaLabelstring | nullnull
aria-descriptionhostAriaDescriptionstring | nullnull
aria-labelledbyhostAriaLabelledBystring | nullnull
aria-describedbyhostAriaDescribedBystring | nullnull
label-positionlabelPosition'top' | 'start' | 'end' | undefined—
hinthintstring—
errorerror——
warningwarningstring | undefined—
successsuccessstring | undefined—
error-messageerrorMessagestring | undefined—
warning-messagewarningMessagestring | undefined—
warning-patternwarningPatternstring | undefined—
labellabelstring—
valuevaluestring—
placeholderplaceholderstring—
allow-customallowCustombooleanfalse
autocompleteautocompleteAutoFilloff
multiplemultiplebooleanfalse
clearableclearablebooleanfalse
select-allselectAllbooleanfalse
maxmaxnumber0

Methods

MethodDescription
describedByIds()IDs to add to the inner control's aria-describedby: the hint, then the shown message.
checkValidity()True when the value is valid; otherwise fires invalid and returns false, like native.
reportValidity()Like checkValidity(), and also shows the browser's validation message when invalid.
setCustomValidity(message)Set (non-empty) or clear (empty string) a custom validation error, like native controls.
setValidityState(flags, message, anchor)For subclasses: set the validity flags and message. anchor is the element the browser points its message at.
validate()Show (or clear) the error from the control's own checks: required, type, pattern, min, max and the like. Uses error-message, else the browser's localized message. An error the author set (a server error, say) is left as it is.
clearValidation()Clear the error and warning that validate() and warning-pattern showed (a form reset does).
emitValue(commit)For subclasses: fire the value events, as a native control does on a user edit: input (bubbles, composed), then with commit also change (bubbles, stays in its tree).
idrefText(ids)For subclasses: the text of the elements an ID reference list names, resolved in the host's tree (ID references cannot cross a shadow root), joined by spaces.
open()Open the list (does nothing while disabled or read-only).
close()Close the list.
clear()Clear the value and the typed text (the clear button).

Events

EventDescription
inputFired on every user edit of the value.
changeFired when the user commits a change to the value or state.

CSS parts

Style the inside of the component with ::part(), for example focsd-combobox::part(active).

PartDescription
activeAdded to the highlighted option.
layoutThe wrapper holding the label and the body; its `data-position` is the label position.
bodyThe field, then the hint and the message.
hintThe author's hint.
messageThe shown error, warning or success message (also named by its kind).
message-iconThe icon in the message.
announcerThe live region that announces a changed message.
controlThe control element.
fieldThe bordered row holding the chosen tags, the input and the clear button.
labelThe label element.
popupThe popup holding the listbox.
listboxThe listbox element.
optionThe option element.
groupAn option group.
group-labelAn option group's label.
select-allThe Select all row (with `multiple select-all`).
clearThe clear button (with `clearable`).
statusThe status element.
tagsThe chosen values (with `multiple`).
tagA chosen value.
removeA chosen value's remove button.

Accessibility

  • autocomplete is forwarded to the input (for example country-name, WCAG 1.3.5).
  • APG combobox with list autocomplete: focus stays in the input and the active option is referenced with aria-activedescendant.
  • Slotted focsd-options are data; the visible list is rendered inside the same shadow root as the input, so the reference never crosses a shadow boundary.
  • A polite status announces the result count ("3 results", "No results").
  • focsd-option-group children render as named groups in the list; a group hides when none of its options match.
  • multiple turns it into a multi-select (the same as focsd-multi-select). clearable adds a "Clear <label>" button.
  • Typed text that does not match an option is discarded on blur; clearing the text clears the value. Set allow-custom to accept free text.
  • Form-associated: participates in FormData, validation, reset, fieldset disabled and back/forward restore.

Keyboard

KeyAction
Arrow Down / UpOpen and move through options
Alt + Arrow DownOpen without moving
EnterChoose the active option
EscapeClose; press again to clear