Select
A single choice from a list. Renders a native select, so the option list is
the platform's — correct on touch devices and with a screen reader, at the cost
of not being stylable.
import { Select } from "antlitz";
API
| Prop | Type | Default |
|---|---|---|
| radius | "none" | "sm" | "md" | "lg" | "full" | none |
| size | "sm" | "md" | "lg" | md |
| variant | "outline" | "soft" | "plain" | outline |
Like Input, the native size attribute is removed from the type so it cannot
collide with the variant prop.
Variants
export function Variants() {
return (
<>
{(["outline", "soft", "plain"] as const).map((variant) => (
<Select key={variant} variant={variant} defaultValue={variant}>
<option value={variant}>{variant}</option>
</Select>
))}
</>
);
}Sizes
export function Sizes() {
return (
<>
{(["sm", "md", "lg"] as const).map((size) => (
<Select key={size} size={size} defaultValue={size}>
<option value={size}>{size}</option>
</Select>
))}
</>
);
}Heights match Input exactly at every size, so the two line up in a form.
Radius
export function Radius() {
return RADII.map((radius) => (
<Select key={radius} radius={radius} defaultValue={radius}>
<option value={radius}>{radius}</option>
</Select>
));
}States
export function States() {
return (
<>
<Select disabled defaultValue="a">
<option value="a">Disabled</option>
</Select>
<Select aria-invalid defaultValue="a">
<option value="a">Invalid</option>
</Select>
<Select multiple defaultValue={["a"]} className="h-auto">
<option value="a">Multiple</option>
<option value="b">No chevron</option>
</Select>
</>
);
}The chevron is decorative and hidden from assistive technology; it is omitted
entirely when multiple is set, since a multi-select has no collapsed state to
indicate. It sits at the inline end, so it moves to the left in a
right-to-left page.
Composition
Used for scheduling.
export function Composition() {
return (
<Field
label="Timezone"
description="Used for scheduling."
className="w-full max-w-xs"
>
<Select defaultValue="Europe/Berlin">
<option>Europe/Berlin</option>
<option>Asia/Tokyo</option>
</Select>
</Field>
);
}