Skip to content

Combobox

A text field that filters a list as you type, for picking one value from many. Same markup and props in every style: switch the style in the header to see it change.

Basic

Type to filter, ↓ ↑ to move, Enter to choose, Esc to close. In HTML, add data-vin-combobox and include vinui.js once.

Astro
Angular
Next.js
Nuxt
Remix
SolidStart
SvelteKit
combobox-basic.html
<div class="vin-field" style="width: 100%; max-width: 320px">
  <label class="vin-label" for="cbx-fw">Framework</label>
  <div class="vin-combobox" data-vin-combobox>
    <input id="cbx-fw" class="vin-input vin-combobox__input" type="text" role="combobox" aria-autocomplete="list" aria-expanded="false" aria-controls="cbx-fw-list" autocomplete="off" placeholder="Search frameworks…">
    <div class="vin-select__content vin-combobox__content" popover="manual">
      <div id="cbx-fw-list" role="listbox" aria-label="Framework">
        <div class="vin-select__item" id="cbx-fw-opt-0" role="option" aria-selected="false" data-value="astro">Astro</div>
        <div class="vin-select__item" id="cbx-fw-opt-1" role="option" aria-selected="false" data-value="angular">Angular</div>
        <div class="vin-select__item" id="cbx-fw-opt-2" role="option" aria-selected="false" data-value="next">Next.js</div>
        <div class="vin-select__item" id="cbx-fw-opt-3" role="option" aria-selected="false" data-value="nuxt">Nuxt</div>
        <div class="vin-select__item" id="cbx-fw-opt-4" role="option" aria-selected="false" data-value="remix">Remix</div>
        <div class="vin-select__item" id="cbx-fw-opt-5" role="option" aria-selected="false" data-value="solid">SolidStart</div>
        <div class="vin-select__item" id="cbx-fw-opt-6" role="option" aria-selected="false" data-value="sveltekit">SvelteKit</div>
      </div>
      <p class="vin-combobox__empty" role="status" hidden>No results.</p>
    </div>
    <input type="hidden" name="framework" value="">
  </div>
</div>

Groups

Options under headings. Headings disappear when none of their options match.

Kolkata
Singapore
Tokyo
Berlin
London
Paris
New York
São Paulo
Los Angeles
combobox-groups.html
<div class="vin-field" style="width: 100%; max-width: 320px">
  <label class="vin-label" for="cbx-tz">Time zone</label>
  <div class="vin-combobox" data-vin-combobox>
    <input id="cbx-tz" class="vin-input vin-combobox__input" type="text" role="combobox" aria-autocomplete="list" aria-expanded="false" aria-controls="cbx-tz-list" autocomplete="off" placeholder="Search…" value="London">
    <div class="vin-select__content vin-combobox__content" popover="manual">
      <div id="cbx-tz-list" role="listbox" aria-label="Time zone">
        <div class="vin-combobox__group" role="group" aria-labelledby="cbx-tz-g0">
          <div class="vin-combobox__label" id="cbx-tz-g0" role="presentation">Asia</div>
          <div class="vin-select__item" id="cbx-tz-opt-0" role="option" aria-selected="false" data-value="Asia/Kolkata">Kolkata</div>
          <div class="vin-select__item" id="cbx-tz-opt-1" role="option" aria-selected="false" data-value="Asia/Singapore">Singapore</div>
          <div class="vin-select__item" id="cbx-tz-opt-2" role="option" aria-selected="false" data-value="Asia/Tokyo">Tokyo</div>
        </div>
        <div class="vin-combobox__group" role="group" aria-labelledby="cbx-tz-g1">
          <div class="vin-combobox__label" id="cbx-tz-g1" role="presentation">Europe</div>
          <div class="vin-select__item" id="cbx-tz-opt-3" role="option" aria-selected="false" data-value="Europe/Berlin">Berlin</div>
          <div class="vin-select__item" id="cbx-tz-opt-4" role="option" aria-selected="true" data-value="Europe/London">London</div>
          <div class="vin-select__item" id="cbx-tz-opt-5" role="option" aria-selected="false" data-value="Europe/Paris">Paris</div>
        </div>
        <div class="vin-combobox__group" role="group" aria-labelledby="cbx-tz-g2">
          <div class="vin-combobox__label" id="cbx-tz-g2" role="presentation">Americas</div>
          <div class="vin-select__item" id="cbx-tz-opt-6" role="option" aria-selected="false" data-value="America/New_York">New York</div>
          <div class="vin-select__item" id="cbx-tz-opt-7" role="option" aria-selected="false" data-value="America/Sao_Paulo">São Paulo</div>
          <div class="vin-select__item" id="cbx-tz-opt-8" role="option" aria-selected="false" data-value="America/Los_Angeles">Los Angeles</div>
        </div>
      </div>
      <p class="vin-combobox__empty" role="status" hidden>No time zones found.</p>
    </div>
    <input type="hidden" name="timezone" value="Europe/London">
  </div>
</div>

Error and disabled

An error is read out with the field; a disabled combobox can't be focused.

Australia
Canada
India
Japan
United Kingdom

Choose your country.

English
Hindi
combobox-states.html
<div style="display: grid; gap: 16px; width: 100%; max-width: 320px">
  <div class="vin-field">
    <label class="vin-label" for="cbx-country">Country</label>
    <div class="vin-combobox" data-vin-combobox>
      <input id="cbx-country" class="vin-input vin-combobox__input" type="text" role="combobox" aria-autocomplete="list" aria-expanded="false" aria-controls="cbx-country-list" autocomplete="off" placeholder="Search countries…" aria-invalid="true" aria-describedby="cbx-country-error">
      <div class="vin-select__content vin-combobox__content" popover="manual">
        <div id="cbx-country-list" role="listbox" aria-label="Country">
          <div class="vin-select__item" id="cbx-country-opt-0" role="option" aria-selected="false" data-value="au">Australia</div>
          <div class="vin-select__item" id="cbx-country-opt-1" role="option" aria-selected="false" data-value="ca">Canada</div>
          <div class="vin-select__item" id="cbx-country-opt-2" role="option" aria-selected="false" data-value="in">India</div>
          <div class="vin-select__item" id="cbx-country-opt-3" role="option" aria-selected="false" aria-disabled="true" data-value="jp">Japan</div>
          <div class="vin-select__item" id="cbx-country-opt-4" role="option" aria-selected="false" data-value="gb">United Kingdom</div>
        </div>
        <p class="vin-combobox__empty" role="status" hidden>No results.</p>
      </div>
    </div>
    <p class="vin-error" id="cbx-country-error">Choose your country.</p>
  </div>
  <div class="vin-field">
    <label class="vin-label" for="cbx-lang">Language</label>
    <div class="vin-combobox" data-vin-combobox>
      <input id="cbx-lang" class="vin-input vin-combobox__input" type="text" role="combobox" aria-autocomplete="list" aria-expanded="false" aria-controls="cbx-lang-list" autocomplete="off" placeholder="Search…" value="English" disabled>
      <div class="vin-select__content vin-combobox__content" popover="manual">
        <div id="cbx-lang-list" role="listbox" aria-label="Language">
          <div class="vin-select__item" id="cbx-lang-opt-0" role="option" aria-selected="true" data-value="en">English</div>
          <div class="vin-select__item" id="cbx-lang-opt-1" role="option" aria-selected="false" data-value="hi">Hindi</div>
        </div>
        <p class="vin-combobox__empty" role="status" hidden>No results.</p>
      </div>
    </div>
  </div>
</div>

Installation

React, Vue and Svelte: add the component to your project with the CLI. It reads your framework from vin.json and also copies any component this one needs. Then import it:

Terminal
npx @vinish/ui add combobox
React
import { Combobox } from "@/components/vin/combobox";
Vue
import Combobox from "@/components/vin/combobox.vue";
Svelte
import Combobox from "$lib/components/vin/combobox.svelte";

The import paths assume the default folders: @/components/vin (React and Vue, with the usual @ → src alias) and $lib/components/vin (SvelteKit). Use your own if you chose another folder in init. How the Vue and Svelte versions pass values and content is in Frameworks.

Plain HTML: the classes come with the style's stylesheet. This component also needs vinui.js for its keyboard and pointer behaviour.

API

From spec/combobox.json, which every framework version is tested against.

PropValuesDefaultIn HTML
options
The choices. Options with the same group are shown under one heading.
(string | { value, label, disabled?, group? })[]—<div class="vin-select__item" role="option" data-value="…">, inside .vin-combobox__group for headings
value / defaultValue
The chosen value (controlled or not). Use onValueChange to hear about changes.
string—aria-selected="true" on the option, the hidden input's value
label
Visible label. Without it, pass an aria-label.
ReactNode—<label class="vin-label" for="…">
placeholderstringSearch…placeholder on the input
emptyText
Shown when nothing matches.
ReactNodeNo results.<p class="vin-combobox__empty" role="status">
filter
Your own matching. The default matches any part of the label, ignoring case and accents.
(option, query) => boolean——
hint / error
Help text, or an error that also marks the field invalid.
ReactNode—aria-describedby, aria-invalid="true"
sizesmmdlgmdvin-input--{value}
name
Adds a hidden input so the chosen value is submitted with forms.
string—<input type="hidden" name="…">
disabledbooleanfalsedisabled on the input

Parts

React, Vue, SvelteHTML classes
<Combobox>.vin-combobox.vin-combobox__input.vin-combobox__content.vin-combobox__group.vin-combobox__label.vin-combobox__empty

Accessibility

  • Follows the WAI-ARIA combobox pattern with list autocomplete: role="combobox" on the input, aria-expanded, aria-controls, and a role="listbox" of role="option" items.
  • Focus stays in the input while you move through the list; aria-activedescendant tells screen readers which option is highlighted.
  • Keys: type to filter, ↓ ↑ to move (↓ opens), Home End PageUp PageDown, Enter chooses, Esc closes (a second Esc clears), Alt+↓ opens without moving.
  • When focus leaves, the text goes back to the chosen option, so the field never shows a value that isn't selected.
  • "No results" is a status message, so screen readers announce it.