humanonlyweb/ui

Combobox

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

Markdown

Examples

Basic

  • Argentina
  • Australia
  • Brazil
  • Canada
  • Egypt
  • France
  • Germany
  • Ghana
  • India
  • Japan
  • Kenya
  • Mexico
  • Nigeria
  • Norway
  • Portugal
  • South Africa
  • Spain
  • Sweden
  • United Kingdom
  • United States
Copy code

Tags

With multiple, picks show as chips. With creatable, Enter on new text emits create so you can add it.

vuecss
  • vue
  • nuxt
  • css
  • typescript
  • accessibility
  • ssr
Selected: vue, css

Enter adds a new tag. Backspace removes the last.

Copy code

Async options

Fetch matches as v-model:query changes, and set ignore-filter so your results show as they are. Set loading while a request runs.

  • Ada Lovelace
  • Alan Turing
  • Grace Hopper
  • Katherine Johnson
  • Linus Torvalds
  • Margaret Hamilton
Copy code

API

PropTypeDefault
options

Options to choose from.

SelectOption<T>[][]
label

Visible label, linked to the input.

string—
hint

Help text under the control, announced as its description.

string—
error

true marks the control invalid; a string also shows it as the message, replacing the hint.

string | boolean—
placeholder

Input placeholder.

string—
multiple

Pick several; v-model becomes an array, shown as chips. Backspace removes the last one.

booleanfalse
creatable

Enter on text matching no option emits create with it.

booleanfalse
optional

Appends the optional translation to the label.

booleanfalse
disabled

Disables the control.

booleanfalse
filter

Custom match for each option against the lower-cased query. By default, labels are ranked exact, then prefix, then substring.

ComboboxFilter<T>—
ignoreFilter

Show options as given, without filtering, e.g. results from a search request.

booleanfalse
loading

Options are being fetched: shows the loading translation and marks the list busy.

booleanfalse
name

Form field name: submits the value with a native form, via hidden inputs.

string—
id

Id for the input; generated with useId() when omitted.

string—
modelValue

The selected value, or values with multiple.

T | T[]—
query

The input's text. Bind it to fetch options as the user types.

string""
EventPayload
create

Enter was pressed on text matching no option (with creatable).

[query: string]
update:modelValue

v-model:modelValue update.

[value: T | T[] | undefined]
update:query

v-model:query update.

[value: string]
SlotProps
option

Option content.

{ option: SelectOption<T>; selected: boolean; active: boolean; }
chip

Each selected value in multiple mode. Call remove to deselect it.

{ option: SelectOption<T>; remove: () => void; }
empty

Shown when nothing matches.

{ query: string; }
create

Shown with creatable when Enter would create the typed value.

{ query: string; }
loading

Shown while loading.

—

Types

export interface SelectOption<T extends SelectValue = SelectValue> {
  label: string;
  value: T;
  disabled?: boolean;
}

export type ComboboxFilter<T extends SelectValue> = (
  option: SelectOption<T>,
  query: string,
) => boolean;

export type SelectValue = string | number;
Copy code

Styling

Parts
fieldfield-labelfield-optionalcombobox-controlcombobox-chipcombobox-chip-labelcombobox-chip-removecombobox-inputcombobox-popupcombobox-listboxcombobox-optioncombobox-option-labelcombobox-loadingcombobox-createcombobox-emptycombobox-statusfield-message
States
data-field-errordata-field-namedata-combobox-opendata-combobox-disableddata-combobox-activedata-field-tone

Keyboard

KeysAction
TypingFilter, and open the list
↓ / ↑Move between options, wrapping
Alt + ↓Open without moving
EnterSelect the active option, or create (with creatable)
EscapeClose; press again to clear
BackspaceWith multiple and an empty input, remove the last chip

Accessibility

  • Focus stays in the input; screen readers follow the highlighted option through aria-activedescendant.
  • While typing, a hidden status announces the number of matches, “No results”, or “Loading…”.
  • Chips aren't in the tab order, so with multiple the picks are read as part of the input's description.
  • In single mode, leaving the input with unmatched text restores the selection.