Skip to content

Select

Pick one value from a list that matches your style, with full keyboard support. Same markup and props in every style: switch the style in the header to see it change.

Basic

Click or press ↓ to open, type a letter to jump, Enter to choose. In HTML, add data-vin-select and include vinui.js once.

Framework
Astro
Next.js
Nuxt
Remix
SvelteKit
select-basic.html
<div class="vin-field" style="width: 100%; max-width: 320px">
  <span class="vin-label" id="fw-label">Framework</span>
  <div class="vin-select" data-vin-select>
    <button type="button" id="fw" class="vin-input vin-select__trigger" role="combobox" aria-haspopup="listbox" aria-expanded="false" aria-controls="fw-list" aria-labelledby="fw-label">
      <span class="vin-select__value">Astro</span>
    </button>
    <div class="vin-select__content" id="fw-list" role="listbox" popover="manual" tabindex="-1" aria-labelledby="fw-label">
      <div class="vin-select__item" id="fw-opt-0" role="option" aria-selected="true" data-value="astro">Astro</div>
      <div class="vin-select__item" id="fw-opt-1" role="option" aria-selected="false" data-value="next">Next.js</div>
      <div class="vin-select__item" id="fw-opt-2" role="option" aria-selected="false" data-value="nuxt">Nuxt</div>
      <div class="vin-select__item" id="fw-opt-3" role="option" aria-selected="false" data-value="remix">Remix</div>
      <div class="vin-select__item" id="fw-opt-4" role="option" aria-selected="false" data-value="sveltekit">SvelteKit</div>
    </div>
    <input type="hidden" name="framework" value="astro">
  </div>
</div>

Placeholder, error, disabled

Show a placeholder until something is chosen, an error that is read out with the field, or a disabled select.

Time zone
India (IST)
London (GMT)
Los Angeles (PST)
Tokyo (JST)

Choose a time zone.

Currency
INR
USD
select-states.html
<div style="display: grid; gap: 16px; width: 100%; max-width: 320px">
  <div class="vin-field">
    <span class="vin-label" id="tz-label">Time zone</span>
    <div class="vin-select" data-vin-select>
      <button type="button" id="tz" class="vin-input vin-select__trigger" role="combobox" aria-haspopup="listbox" aria-expanded="false" aria-controls="tz-list" aria-labelledby="tz-label" aria-invalid="true" aria-describedby="tz-error">
        <span class="vin-select__value" data-placeholder>Choose a time zone</span>
      </button>
      <div class="vin-select__content" id="tz-list" role="listbox" popover="manual" tabindex="-1" aria-labelledby="tz-label">
        <div class="vin-select__item" id="tz-opt-0" role="option" aria-selected="false" data-value="ist">India (IST)</div>
        <div class="vin-select__item" id="tz-opt-1" role="option" aria-selected="false" data-value="gmt">London (GMT)</div>
        <div class="vin-select__item" id="tz-opt-2" role="option" aria-selected="false" aria-disabled="true" data-value="pst">Los Angeles (PST)</div>
        <div class="vin-select__item" id="tz-opt-3" role="option" aria-selected="false" data-value="jst">Tokyo (JST)</div>
      </div>
    </div>
    <p class="vin-error" id="tz-error">Choose a time zone.</p>
  </div>
  <div class="vin-field">
    <span class="vin-label" id="cur-label">Currency</span>
    <div class="vin-select" data-vin-select>
      <button type="button" id="cur" class="vin-input vin-select__trigger" role="combobox" aria-haspopup="listbox" aria-expanded="false" aria-controls="cur-list" aria-labelledby="cur-label" disabled>
        <span class="vin-select__value">INR</span>
      </button>
      <div class="vin-select__content" id="cur-list" role="listbox" popover="manual" tabindex="-1" aria-labelledby="cur-label">
        <div class="vin-select__item" id="cur-opt-0" role="option" aria-selected="true" data-value="INR">INR</div>
        <div class="vin-select__item" id="cur-opt-1" role="option" aria-selected="false" data-value="USD">USD</div>
      </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 select
React
import { Select } from "@/components/vin/select";
Vue
import Select from "@/components/vin/select.vue";
Svelte
import Select from "$lib/components/vin/select.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/select.json, which every framework version is tested against.

PropValuesDefaultIn HTML
options
The choices.
(string | { value, label, disabled? })[]—<div class="vin-select__item" role="option" data-value="…">
value / defaultValue
The chosen value (controlled or not). Use onValueChange to hear about changes.
string—aria-selected="true" on the option
label
Visible label. Without it, pass an aria-label.
ReactNode—<span class="vin-label" id="…"> + aria-labelledby
placeholderstringSelect…<span class="vin-select__value" data-placeholder>
hint / error
Help text, or an error that also marks the select invalid.
ReactNode—aria-describedby, aria-invalid="true"
sizesmmdlgmdvin-input--{value}
name
Adds a hidden input so the value is submitted with forms.
string—<input type="hidden" name="…">
disabledbooleanfalsedisabled on the button

Parts

React, Vue, SvelteHTML classes
<Select>.vin-select.vin-select__trigger.vin-select__value.vin-select__content.vin-select__item

Accessibility

  • Follows the WAI-ARIA select-only combobox pattern: role="combobox" on the button, role="listbox" and role="option" for the list.
  • Focus stays on the button; aria-activedescendant tells screen readers which option is highlighted.
  • Keys: ↑ ↓ Home End PageUp PageDown to move, Enter or Space to choose, Esc to close, Tab chooses and moves on, letters jump to matching options.
  • The list opens in the top layer and flips above the button when there's no room below.
  • Need it to work without JavaScript? Use Native Select.