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.
<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>import { Select } from "@/components/vin/select";
const frameworks = [
{ value: "astro", label: "Astro" },
{ value: "next", label: "Next.js" },
{ value: "nuxt", label: "Nuxt" },
{ value: "remix", label: "Remix" },
{ value: "sveltekit", label: "SvelteKit" },
];
export function SelectBasic() {
return <Select label="Framework" options={frameworks} defaultValue="astro" 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 Select from "@/components/vin/select.vue";
const frameworks = [
{ value: "astro", label: "Astro" },
{ value: "next", label: "Next.js" },
{ value: "nuxt", label: "Nuxt" },
{ value: "remix", label: "Remix" },
{ value: "sveltekit", label: "SvelteKit" },
];
</script>
<template>
<Select label="Framework" :options="frameworks" default-value="astro" 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 Select from "$lib/components/vin/select.svelte";
const frameworks = [
{ value: "astro", label: "Astro" },
{ value: "next", label: "Next.js" },
{ value: "nuxt", label: "Nuxt" },
{ value: "remix", label: "Remix" },
{ value: "sveltekit", label: "SvelteKit" },
];
</script>
<Select label="Framework" options={frameworks} value="astro" name="framework" style="width: 100%; max-width: 320px" />Placeholder, error, disabled
Show a placeholder until something is chosen, an error that is read out with the field, or a disabled select.
Choose a time zone.
<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>Choose a time zone.
import { Select } from "@/components/vin/select";
const zones = [
{ value: "ist", label: "India (IST)" },
{ value: "gmt", label: "London (GMT)" },
{ value: "pst", label: "Los Angeles (PST)", disabled: true },
{ value: "jst", label: "Tokyo (JST)" },
];
export function SelectStates() {
return (
<div style={{ display: "grid", gap: 16, width: "100%", maxWidth: 320 }}>
<Select label="Time zone" options={zones} placeholder="Choose a time zone" error="Choose a time zone." />
<Select label="Currency" options={["INR", "USD"]} defaultValue="INR" 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 Select from "@/components/vin/select.vue";
const zones = [
{ value: "ist", label: "India (IST)" },
{ value: "gmt", label: "London (GMT)" },
{ value: "pst", label: "Los Angeles (PST)", disabled: true },
{ value: "jst", label: "Tokyo (JST)" },
];
</script>
<template>
<div style="display: grid; gap: 16px; width: 100%; max-width: 320px">
<Select label="Time zone" :options="zones" placeholder="Choose a time zone" error="Choose a time zone." />
<Select label="Currency" :options="['INR', 'USD']" default-value="INR" 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 Select from "$lib/components/vin/select.svelte";
const zones = [
{ value: "ist", label: "India (IST)" },
{ value: "gmt", label: "London (GMT)" },
{ value: "pst", label: "Los Angeles (PST)", disabled: true },
{ value: "jst", label: "Tokyo (JST)" },
];
</script>
<div style="display: grid; gap: 16px; width: 100%; max-width: 320px">
<Select label="Time zone" options={zones} placeholder="Choose a time zone" error="Choose a time zone." />
<Select label="Currency" options={["INR", "USD"]} value="INR" 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 selectimport { Select } from "@/components/vin/select";import Select from "@/components/vin/select.vue";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.
| Prop | Values | Default | In HTML |
|---|---|---|---|
optionsThe choices. | (string | { value, label, disabled? })[] | — | <div class="vin-select__item" role="option" data-value="…"> |
value / defaultValueThe chosen value (controlled or not). Use onValueChange to hear about changes. | string | — | aria-selected="true" on the option |
labelVisible label. Without it, pass an aria-label. | ReactNode | — | <span class="vin-label" id="…"> + aria-labelledby |
placeholder | string | Select… | <span class="vin-select__value" data-placeholder> |
hint / errorHelp text, or an error that also marks the select invalid. | ReactNode | — | aria-describedby, aria-invalid="true" |
size | smmdlg | md | vin-input--{value} |
nameAdds a hidden input so the value is submitted with forms. | string | — | <input type="hidden" name="…"> |
disabled | boolean | false | disabled on the button |
Parts
| React, Vue, Svelte | HTML 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.
Customize
Saved in this browser. Style and accent are in the header.