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.
No results.
<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>No results.
import { Combobox } from "@/components/vin/combobox";
const frameworks = [
{ value: "astro", label: "Astro" },
{ value: "angular", label: "Angular" },
{ value: "next", label: "Next.js" },
{ value: "nuxt", label: "Nuxt" },
{ value: "remix", label: "Remix" },
{ value: "solid", label: "SolidStart" },
{ value: "sveltekit", label: "SvelteKit" },
];
export function ComboboxBasic() {
return <Combobox label="Framework" options={frameworks} placeholder="Search frameworks…" name="framework" style={{ width: "100%", maxWidth: 320 }} />;
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import Combobox from "@/components/vin/combobox.vue";
const frameworks = [
{ value: "astro", label: "Astro" },
{ value: "angular", label: "Angular" },
{ value: "next", label: "Next.js" },
{ value: "nuxt", label: "Nuxt" },
{ value: "remix", label: "Remix" },
{ value: "solid", label: "SolidStart" },
{ value: "sveltekit", label: "SvelteKit" },
];
</script>
<template>
<Combobox label="Framework" :options="frameworks" placeholder="Search frameworks…" name="framework" style="width: 100%; max-width: 320px" />
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import Combobox from "$lib/components/vin/combobox.svelte";
const frameworks = [
{ value: "astro", label: "Astro" },
{ value: "angular", label: "Angular" },
{ value: "next", label: "Next.js" },
{ value: "nuxt", label: "Nuxt" },
{ value: "remix", label: "Remix" },
{ value: "solid", label: "SolidStart" },
{ value: "sveltekit", label: "SvelteKit" },
];
</script>
<Combobox label="Framework" options={frameworks} placeholder="Search frameworks…" name="framework" style="width: 100%; max-width: 320px" />Groups
Options under headings. Headings disappear when none of their options match.
No time zones found.
<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>No time zones found.
import { Combobox } from "@/components/vin/combobox";
const zones = [
{ value: "Asia/Kolkata", label: "Kolkata", group: "Asia" },
{ value: "Asia/Singapore", label: "Singapore", group: "Asia" },
{ value: "Asia/Tokyo", label: "Tokyo", group: "Asia" },
{ value: "Europe/Berlin", label: "Berlin", group: "Europe" },
{ value: "Europe/London", label: "London", group: "Europe" },
{ value: "Europe/Paris", label: "Paris", group: "Europe" },
{ value: "America/New_York", label: "New York", group: "Americas" },
{ value: "America/Sao_Paulo", label: "São Paulo", group: "Americas" },
{ value: "America/Los_Angeles", label: "Los Angeles", group: "Americas" },
];
export function ComboboxGroups() {
return (
<Combobox
label="Time zone"
options={zones}
defaultValue="Europe/London"
emptyText="No time zones found."
name="timezone"
style={{ width: "100%", maxWidth: 320 }}
/>
);
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import Combobox from "@/components/vin/combobox.vue";
const zones = [
{ value: "Asia/Kolkata", label: "Kolkata", group: "Asia" },
{ value: "Asia/Singapore", label: "Singapore", group: "Asia" },
{ value: "Asia/Tokyo", label: "Tokyo", group: "Asia" },
{ value: "Europe/Berlin", label: "Berlin", group: "Europe" },
{ value: "Europe/London", label: "London", group: "Europe" },
{ value: "Europe/Paris", label: "Paris", group: "Europe" },
{ value: "America/New_York", label: "New York", group: "Americas" },
{ value: "America/Sao_Paulo", label: "São Paulo", group: "Americas" },
{ value: "America/Los_Angeles", label: "Los Angeles", group: "Americas" },
];
</script>
<template>
<Combobox
label="Time zone"
:options="zones"
default-value="Europe/London"
empty-text="No time zones found."
name="timezone"
style="width: 100%; max-width: 320px"
/>
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import Combobox from "$lib/components/vin/combobox.svelte";
const zones = [
{ value: "Asia/Kolkata", label: "Kolkata", group: "Asia" },
{ value: "Asia/Singapore", label: "Singapore", group: "Asia" },
{ value: "Asia/Tokyo", label: "Tokyo", group: "Asia" },
{ value: "Europe/Berlin", label: "Berlin", group: "Europe" },
{ value: "Europe/London", label: "London", group: "Europe" },
{ value: "Europe/Paris", label: "Paris", group: "Europe" },
{ value: "America/New_York", label: "New York", group: "Americas" },
{ value: "America/Sao_Paulo", label: "São Paulo", group: "Americas" },
{ value: "America/Los_Angeles", label: "Los Angeles", group: "Americas" },
];
</script>
<Combobox label="Time zone" options={zones} value="Europe/London" emptyText="No time zones found." name="timezone" style="width: 100%; max-width: 320px" />Error and disabled
An error is read out with the field; a disabled combobox can't be focused.
No results.
Choose your country.
No results.
<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>No results.
Choose your country.
No results.
import { Combobox } from "@/components/vin/combobox";
const countries = [
{ value: "au", label: "Australia" },
{ value: "ca", label: "Canada" },
{ value: "in", label: "India" },
{ value: "jp", label: "Japan", disabled: true },
{ value: "gb", label: "United Kingdom" },
];
export function ComboboxStates() {
return (
<div style={{ display: "grid", gap: 16, width: "100%", maxWidth: 320 }}>
<Combobox label="Country" options={countries} placeholder="Search countries…" error="Choose your country." />
<Combobox label="Language" options={[{ value: "en", label: "English" }, { value: "hi", label: "Hindi" }]} defaultValue="en" disabled />
</div>
);
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import Combobox from "@/components/vin/combobox.vue";
const countries = [
{ value: "au", label: "Australia" },
{ value: "ca", label: "Canada" },
{ value: "in", label: "India" },
{ value: "jp", label: "Japan", disabled: true },
{ value: "gb", label: "United Kingdom" },
];
const languages = [{ value: "en", label: "English" }, { value: "hi", label: "Hindi" }];
</script>
<template>
<div style="display: grid; gap: 16px; width: 100%; max-width: 320px">
<Combobox label="Country" :options="countries" placeholder="Search countries…" error="Choose your country." />
<Combobox label="Language" :options="languages" default-value="en" disabled />
</div>
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import Combobox from "$lib/components/vin/combobox.svelte";
const countries = [
{ value: "au", label: "Australia" },
{ value: "ca", label: "Canada" },
{ value: "in", label: "India" },
{ value: "jp", label: "Japan", disabled: true },
{ value: "gb", label: "United Kingdom" },
];
</script>
<div style="display: grid; gap: 16px; width: 100%; max-width: 320px">
<Combobox label="Country" options={countries} placeholder="Search countries…" error="Choose your country." />
<Combobox label="Language" options={[{ value: "en", label: "English" }, { value: "hi", label: "Hindi" }]} value="en" disabled />
</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:
npx @vinish/ui add comboboximport { Combobox } from "@/components/vin/combobox";import Combobox from "@/components/vin/combobox.vue";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.
| Prop | Values | Default | In HTML |
|---|---|---|---|
optionsThe 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 / defaultValueThe chosen value (controlled or not). Use onValueChange to hear about changes. | string | — | aria-selected="true" on the option, the hidden input's value |
labelVisible label. Without it, pass an aria-label. | ReactNode | — | <label class="vin-label" for="…"> |
placeholder | string | Search… | placeholder on the input |
emptyTextShown when nothing matches. | ReactNode | No results. | <p class="vin-combobox__empty" role="status"> |
filterYour own matching. The default matches any part of the label, ignoring case and accents. | (option, query) => boolean | — | — |
hint / errorHelp text, or an error that also marks the field invalid. | ReactNode | — | aria-describedby, aria-invalid="true" |
size | smmdlg | md | vin-input--{value} |
nameAdds a hidden input so the chosen value is submitted with forms. | string | — | <input type="hidden" name="…"> |
disabled | boolean | false | disabled on the input |
Parts
| React, Vue, Svelte | HTML 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.
Customize
Saved in this browser. Style and accent are in the header.