- Docs
- Components
- 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
// 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.
| Prop | Type | Default | What it does |
|---|---|---|---|
items | SelectItem[] | SelectItemGroup[] | required | The options, flat ({ value, label, disabled, meta }) or in groups ({ label, items }); meta, a count at the end, isn't shown once chosen. |
value · defaultValue | Value | Value[] | — | The chosen value, controlled or to start with; an array with multiple. |
onValueChange | (value, details) => void | — | Called with the new value. |
multiple | boolean | false | Several at once; the trigger lists their labels. |
placeholder | ReactNode | — | 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-label | string | — | Without a Field: the trigger's name. |
03
Parts
Each part carries a data-slot, for tests and placement.
| data-slot | Element | What 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.
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)} />