Radio
One choice from several. Radios sharing a name form a group natively —
including arrow-key navigation and single selection — so no group component is
required to make them behave.
import { Radio } from "antlitz";
API
| Prop | Type | Default |
|---|---|---|
| radius | "none" | "sm" | "md" | "lg" | "full" | full |
| size | "sm" | "md" | "lg" | md |
radius defaults to full rather than none, as on Switch, because a
square radio reads as a checkbox.
Usage
export function Group() {
return (
<Fieldset legend="Notify me about" className="w-full max-w-xs">
<Field orientation="horizontal" label="All new messages">
<Radio name="notify" value="all" defaultChecked />
</Field>
<Field orientation="horizontal" label="Direct messages only">
<Radio name="notify" value="direct" />
</Field>
<Field orientation="horizontal" label="Nothing">
<Radio name="notify" value="none" />
</Field>
</Fieldset>
);
}The shared name is what makes these one group. Fieldset adds the semantic
half: a legend naming the group, and somewhere for a shared error to live.
A group without a legend is announced as a series of unrelated options, so
reach for Fieldset rather than a heading above a plain div.
States
export function States() {
return (
<>
<Radio name="states" aria-label="Unselected" />
<Radio name="states" defaultChecked aria-label="Selected" />
<Radio disabled aria-label="Disabled" />
<Radio disabled defaultChecked aria-label="Disabled selected" readOnly />
<Radio aria-invalid aria-label="Invalid" />
<Radio
aria-invalid
defaultChecked
aria-label="Invalid selected"
readOnly
/>
</>
);
}Sizes
export function Sizes() {
return (
<>
<Radio size="sm" defaultChecked aria-label="Small" readOnly />
<Radio size="md" defaultChecked aria-label="Medium" readOnly />
<Radio size="lg" defaultChecked aria-label="Large" readOnly />
</>
);
}Radius
export function Radius() {
return RADII.map((radius) => (
<Radio
key={radius}
radius={radius}
defaultChecked
readOnly
aria-label={radius}
/>
));
}