Liking cljdoc? Tell your friends :D

x-combobox

A single-select combobox with type-ahead filtering. The user types to filter a list of <option> children; the value must match one of the provided options.

Tag name

<x-combobox>...</x-combobox>

Observed attributes

AttributeTypeDefaultDescription
valuestring""Selected option value
placeholderstring""Input placeholder text
namestring""Form field name
disabledbooleanfalseDisables the component
requiredbooleanfalseMarks as required for form validation
openbooleanfalseControls panel visibility
placementenum"bottom-start"Panel position relative to input

Placement values

bottom-start | bottom-end | top-start | top-end

Properties (camelCase, reflect attributes)

PropertyTypeReflected attribute
valuestringvalue
placeholderstringplaceholder
namestringname
disabledbooleandisabled
requiredbooleanrequired
openbooleanopen
placementstringplacement

Public methods

MethodDescription
show()Opens the dropdown panel (source: "programmatic")
hide()Closes the dropdown panel (source: "programmatic")

Events

x-combobox-change

Fired when the selected value changes (option selection or clear).

PropertyValue
bubblestrue
composedtrue
cancelablefalse
detail.valueSelected option value (string)
detail.labelSelected option label (string)

x-combobox-input

Fired on every filter keystroke.

PropertyValue
bubblestrue
composedtrue
cancelablefalse
detail.queryCurrent filter text (string)

x-combobox-toggle

Fired before the panel opens or closes. Cancelable — call event.preventDefault() to abort.

PropertyValue
bubblestrue
composedtrue
cancelabletrue
detail.openTarget open state (boolean)
detail.sourceWhat triggered: "focus", "pointer", "keyboard", "input", "escape", "select", "outside-click", "focusout", "programmatic"

Slots

SlotDescription
(default)<option> elements providing the available choices

Shadow parts

PartDescription
wrapperOuter container (input + clear + chevron)
inputText input for filtering
clearClear selection button
chevronDropdown arrow indicator
panelDropdown listbox container
optionIndividual option item in panel
empty-msg"No matches" message when filter has no results

CSS custom properties

Layout

PropertyDefaultDescription
--x-combobox-height2.25remInput height
--x-combobox-radiusvar(--x-radius-md, 6px)Border radius
--x-combobox-font-sizevar(--x-font-size-sm, 0.9375rem)Font size
--x-combobox-padding0 0.625remInput padding
--x-combobox-panel-max-height16remMax dropdown height
--x-combobox-panel-offset4pxGap between input and panel
--x-combobox-panel-radiusvar(--x-radius-md, 8px)Panel border radius
--x-combobox-option-padding0.5rem 0.625remOption padding

Colors

PropertyDefaultDescription
--x-combobox-bgvar(--x-color-surface)Input background
--x-combobox-fgvar(--x-color-text)Text color
--x-combobox-placeholdervar(--x-color-text-muted)Placeholder color
--x-combobox-border1px solid var(--x-color-border)Input border
--x-combobox-focus-ringvar(--x-color-focus-ring)Focus ring color
--x-combobox-panel-bgvar(--x-color-bg)Panel background
--x-combobox-option-hover-bgvar(--x-color-surface-hover)Option hover
--x-combobox-option-active-bgvar(--x-color-primary)Active/highlighted option

Motion

PropertyDefaultDescription
--x-combobox-transition-durationvar(--x-transition-duration, 150ms)Animation duration
--x-combobox-transition-easingvar(--x-transition-easing, ease)Animation easing

Accessibility

  • Input has role="combobox", aria-expanded, aria-autocomplete="list", aria-controls pointing to listbox ID
  • Panel has role="listbox" with a unique auto-generated ID
  • Each option has role="option", unique ID, aria-selected for current value
  • Active/highlighted option tracked via aria-activedescendant on input
  • focusin on input opens the panel immediately — keyboard users get immediate feedback
  • Escape closes panel and reverts input text to current selection

Note: required reflects the attribute for styling purposes (e.g. :host([required])) but native form validation via ElementInternals is not yet implemented.

Keyboard navigation

KeyAction
Arrow DownOpen panel (if closed) or move to next option
Arrow UpOpen panel (if closed) or move to previous option
EnterSelect highlighted option, close panel
EscapeClose panel, revert input
HomeJump to first option
EndJump to last option

Filtering

  • Case-insensitive substring match on option label text
  • Matching text is highlighted with bold in the dropdown
  • Empty filter shows all options
  • Value only changes when user explicitly selects (Enter or click)
  • On close without selection, input reverts to current selected label

Usage examples

Basic

<x-combobox placeholder="Select a country">
  <option value="us">United States</option>
  <option value="uk">United Kingdom</option>
  <option value="nl">Netherlands</option>
</x-combobox>

Pre-selected value

<x-combobox value="nl" placeholder="Select a country">
  <option value="us">United States</option>
  <option value="nl">Netherlands</option>
</x-combobox>

Disabled

<x-combobox disabled placeholder="Not available">
  <option value="a">Option A</option>
</x-combobox>

In a form

<form>
  <x-combobox name="country" required placeholder="Required">
    <option value="us">United States</option>
    <option value="uk">United Kingdom</option>
  </x-combobox>
  <button type="submit">Submit</button>
</form>

Programmatic control

const cb = document.querySelector('x-combobox');
cb.show();   // open panel
cb.hide();   // close panel
cb.value = 'uk';  // set selection

Can you improve this documentation?Edit on GitHub

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close