Skip to main content
  1. Docs
  2. Components
  3. Forms

Select

One option, or several, from up to about fifteen: a field that opens its list below.

Import
@qeetrix/react
Status
StableSince 0.0.2
Renders
<button> + listServer-rendered
Tested
WCAG 2.2 AAaxe on every pull request

01

Import

select.tsx
// From the package: a build keeps only what it uses.
import { Select, Field } from "@qeetrix/react";

// Or from its own path.
import { Select, Field } from "@qeetrix/react/select";

02

Props

And every native attribute of the element it renders.

PropTypeDefaultWhat it does
itemsSelectItem[] | SelectItemGroup[]requiredThe options, flat ({ value, label, disabled, meta }) or in groups ({ label, items }); meta, a count at the end, isn't shown once chosen.
value · defaultValueValue | Value[]—The chosen value, controlled or to start with; an array with multiple.
onValueChange(value, details) => void—Called with the new value.
multiplebooleanfalseSeveral at once; the trigger lists their labels.
placeholderReactNode—Shown while nothing's chosen: an example, never an instruction.
size"sm" | "md" | "lg""lg"lg, a form field's; md or sm beside Buttons of that size in a toolbar.
disabled · required · name…—As on a form control; name submits the value.
aria-labelstring—Without a Field: the trigger's name.

03

Parts

Each part carries a data-slot, for tests and placement.

data-slotElementWhat it is
select-trigger<button>The box: ref lands here, and a Field labels it.
select-value<span>The chosen label, or the placeholder.
select-popup<div>The list, below the trigger, as a menu's.
select-option<div role="option">An option; the chosen one has an Ember check.
select-group-label<div>A group's label.

04

Typed values

Generic over the value: the type follows the items.

cycle.tsx
type Cycle = "monthly" | "quarterly" | "yearly";
const cycles: SelectItem<Cycle>[] = [
  { value: "monthly", label: "Monthly" },
  { value: "quarterly", label: "Quarterly" },
  { value: "yearly", label: "Yearly" },
];

<Select<Cycle> items={cycles} onValueChange={(cycle) => setCycle(cycle)} />
Next — SelectAccessibility