Combobox

A select with a text filter. Multi-select is a mode of it.

Combobox

Needs Alpine. See getting started.

Use it

<x-ds::combobox
    name="country"
    label="Country"
    :options="$countries"
    :value="old('country', $user->country)"
/>

Pick several by adding :multiple="true" — chosen values become removable chips inside the field:

<x-ds::combobox name="tags" label="Tags" :options="$tags" :value="$selected" :multiple="true" />
{{-- posts tags[]=a11y&tags[]=billing --}}

Props

PropTypeDefaultWhat it does
namestringrequiredSubmitted field name. [] is appended for you when multiple.
optionsarray[]value => label. The whole list — filtering is client-side.
valuestring|array—Selected value, or an array of them.
labelstring—Field label.
multipleboolfalsePick several.
placeholderstringSearch…
emptyTextstringNo matchesShown when the filter matches nothing.
helpstring—
errorstring—
disabledboolfalse

Which control

OptionsReach for
under ~15, one choiceselect
under ~12, several choicesa list of checkboxes — more scannable, and free
more than that, or unfamiliar valuesthis

A combobox costs the reader a decision before they can act: they have to guess what to type. Below about fifteen options a plain list is faster, and on a phone the native <select> is faster still.

Filtering is client-side

You pass the whole list and the browser filters it. There is no server-side search — that needs a request, and a request needs a backend contract this system deliberately doesn't have.

For a list too large to send down, you want a different component than this one.

Keyboard

Typing filters. Arrows walk the filtered list, Home and End jump, Enter and Space choose, Escape closes.

Backspace on an empty query removes the last chip — without it, undoing a selection means aiming at a 12px ✕, which on a touch screen isn't a target.

With validation

<x-ds::combobox
    name="country"
    label="Country"
    :options="$countries"
    :value="old('country')"
    :error="$errors->first('country')"
    help="Where the invoice is issued from."
/>

Don't

  • Don't use it under fifteen options. See the table above.
  • Don't use it for actions. A menu of verbs is a dropdown.
  • Don't expect server-side filtering.
  • Don't use multiple where the total is unbounded. Twenty chips wrap the field to four lines and shove the page around.

More in specs/combobox.md.


From the package repo: edit this page on GitHub.

Was this page helpful?