vaiperui

components / select

Select

Accessible combobox with keyboard navigation, type-to-search and a detailed style with an icon/description per option.

How to use

Accessible combobox (`role="combobox"` + `listbox`) with keyboard navigation, typeahead and controlled or uncontrolled selection. Enable `searchable` to filter by text and `variant="detailed"` for options with `leading` and `description`.

preview
Select.tsx
import { Select } from "vaiperui";
<Select
label="Country"
placeholder="Choose a country"
searchable
options={[
{ value: "br", label: "Brazil" },
{ value: "us", label: "United States" },
{ value: "pt", label: "Portugal" },
]}
/>

Colors

preview
primary
success
warning
danger
colors.tsx
<Select variantColor="primary" label="Country" options={options} />
<Select variantColor="success" label="Country" options={options} />
<Select variantColor="warning" label="Country" options={options} />
<Select variantColor="danger" label="Country" options={options} />

Styles

`detailed` enlarges the trigger and the options, with a `leading` slot and a `description` per item.

preview
default
detailed
styles.tsx
<Select variant="default" label="Country" options={options} />
<Select variant="detailed" label="Country" options={options} />

Sizes

preview
sm
md
lg
sizes.tsx
<Select size="sm" label="Country" options={options} />
<Select size="md" label="Country" options={options} />
<Select size="lg" label="Country" options={options} />

Radius

preview
none
sm
md
lg
full
radius.tsx
<Select radius="none" label="Country" options={options} />
<Select radius="sm" label="Country" options={options} />
<Select radius="md" label="Country" options={options} />
<Select radius="lg" label="Country" options={options} />
<Select radius="full" label="Country" options={options} />

`searchable` adds a field to filter the options by text.

preview
searchable
searchStyle full
no search
search.tsx
<Select searchable label="Country" options={options} />
<Select searchable searchStyle="full" label="Country" options={options} />
<Select label="Country" options={options} />

Async loading

`loading` shows a spinner row, `onReachEnd` asks for the next page when the user scrolls to the end (stop it with `hasMore={false}`), and `onSearchChange` moves the search to the server.

preview
infinite scroll
server search
async.tsx
// Infinite scroll
<Select
options={options}
loading={loading}
hasMore={hasMore}
onReachEnd={() => {
setLoading(true);
fetchNextPage().then(() => setLoading(false));
}}
/>
// Server-side search (debounce it yourself)
<Select
searchable
options={options}
loading={loading}
onSearchChange={(query) => search(query)}
/>

States

`disabled` blocks the whole select. An option with `disabled: true` appears blocked and cannot be chosen.

preview
disabled option
disabled
states.tsx
<Select label="Country" options={options} disabled />
const options = [
{ value: "br", label: "Brazil" },
{ value: "pt", label: "Portugal", disabled: true },
]

Custom color

`customColor` overrides `variantColor` and paints focus, border and highlight from a single color.

preview
orange
green
violet
custom-color.tsx
<Select customColor="#ff6600" label="Country" options={options} />
<Select customColor="#22c55e" label="Country" options={options} />
<Select customColor="#a78bfa" label="Country" options={options} />

Props

PropValuesDefaultDescription
optionsSelectOption[]—List of options ({ value, label, disabled?, description?, leading? })
value / defaultValuestring—Controlled / uncontrolled
onValueChange(value: string) => void—Fired when an option is selected
placeholderstring"Select an option"Text shown when nothing is selected
emptyMessagestring"No options found"Text when there are no options
noResultsMessage(query: string) => string(query) => `No results for "${query}"`Text when a search has no matches; receives the typed query
loadingbooleanfalseShows a spinner row at the end of the list while options load
loadingMessagestring"Loading..."Text shown next to the spinner
onReachEnd() => void—Fires when the user scrolls near the end of the list (not while loading): fetch the next page and append it to options
hasMorebooleantrueSet false after the last page. While true, onReachEnd also fires when the options don't fill the menu, until they do
onSearchChange(query: string) => void—Server-side search (needs searchable): called with the typed text and turns off the local filter, so options should already be the matches. Debounce it yourself. It is also called with "" when the search is cleared or the menu reopens with a leftover query, and the selected option keeps its label on the button even when a search removes it from options
searchablebooleanfalseShows a search field inside the menu to filter by text
searchPlaceholderstring"Search..."Search field placeholder
clearSearchLabelstring"Clear search"Accessible name of the button that clears the search
searchStyle"boxed" | "full""boxed"`boxed`: inset, rounded field. `full`: the field spans the whole top of the menu, with a divider
variantdefault | detaileddefaultdefault: compact single-line dropdown. detailed: larger trigger and options, with leading and description per option and a tint on the selected one
variantColorprimary | success | warning | dangerprimaryFocus color, open border and option highlight
customColorvalid CSS color | { light, dark }—Overrides variantColor: paints focus, border and highlight from a single color, or from a { light, dark } object
sizesm | md | lgmdHeight of the trigger and the options
radiusnone | sm | md | lg | fullmdRounding of the trigger and the menu
animationnone | smooth | fast | bouncesmoothMenu transition
disabledbooleanfalseDisables the whole select
namestring—Mirrors the value into an <input type="hidden"> for form submission
label / aria-label / id / className / stylestring / string / string / string / CSSProperties—Label above the trigger, accessible name when there is no label, and layout props
option.leading / option.descriptionReactNode / string—Visual slot (flag, icon, avatar) before the text, and a second line per option. The slot works in both variants; the description only renders with variant="detailed"

Accessibility

  • The trigger is a `<button role="combobox">` with `aria-haspopup="listbox"`, `aria-expanded` and `aria-controls` pointing at the list.
  • The list is `role="listbox"` with `role="option"` items carrying `aria-selected`, plus `aria-disabled` on disabled options.
  • Focus stays on the trigger and the highlighted option is exposed with `aria-activedescendant`; with `searchable`, focus moves to the search field, which holds `aria-activedescendant` instead.
  • `label` is a `<label htmlFor>` for the trigger; `aria-label` is set on it too. The search field is named by `searchPlaceholder`.
  • While `loading`, the listbox has `aria-busy`. Selecting an option or pressing Esc returns focus to the trigger.
  • `disabled` uses the native attribute on the trigger. With `name`, a hidden input carries the value for forms.

Keyboard

KeyAction
Enter / SpaceOpens the list; when open, selects the highlighted option.
ArrowDown / ArrowUpOpens the list; when open, moves the highlight (skipping disabled options).
Home / EndHighlights the first / last option while open.
EscCloses the list; in the search field, also returns focus to the trigger.
TabCloses the list and lets focus move on.
LettersWithout `searchable`, typeahead jumps to the option starting with the typed text.

Keep in mind

  • Without a visible `label`, pass `aria-label`; the component does not name the trigger on its own.
  • The list renders in a portal on `document.body`, outside the field in DOM order, and does not trap focus.
  • Single selection only, and there is no `aria-invalid`/error state: show validation messages yourself.