- 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
Playground
Every prop, live, and the code it takes.
import { Field, Select } from "@qeetrix/react";
const cycles = [
{ value: "monthly", label: "Monthly" },
{ value: "quarterly", label: "Quarterly" },
{ value: "yearly", label: "Yearly" },
];
<Field label="Billing cycle">
<Select items={cycles} placeholder="e.g. Monthly" />
</Field>02
In a field
One of up to about fifteen. Field labels it; the chosen option carries the Ember check.
const cycles = [
{ value: "monthly", label: "Monthly" },
{ value: "quarterly", label: "Quarterly" },
{ value: "yearly", label: "Yearly" },
];
<Field label="Billing cycle">
<Select items={cycles} placeholder="e.g. Monthly" />
</Field>03
Grouped
items in groups, each with its label; an option can be shown but not chosen.
const roles = [
{ label: "Admins", items: [{ value: "owner", label: "Owner" }, { value: "admin", label: "Admin" }, …] },
{ label: "Members", items: [{ value: "member", label: "Member" }, { value: "guest", label: "Guest", disabled: true }, …] },
];
<Field label="Role">
<Select items={roles} defaultValue="member" />
</Field>04
Several
multiple: the trigger lists the chosen labels.
<Field label="Data regions">
<Select items={regions} multiple defaultValue={["mum", "hyd"]} />
</Field>05
Controlled
value and onValueChange: the page follows the choice.
Billed once a year, two months free.
const [cycle, setCycle] = useState<string | null>("yearly");
<Field label="Billing cycle">
<Select items={cycles} value={cycle} onValueChange={setCycle} />
</Field>06
Invalid and disabled
An error from its Field; disabled from its own prop.
Choose how often to bill.
<Stack gap="lg">
<Field label="Billing cycle" error="Choose how often to bill.">
<Select items={cycles} placeholder="e.g. Monthly" />
</Field>
<Field label="Billing cycle">
<Select items={cycles} defaultValue="yearly" disabled />
</Field>
</Stack>