Radio
Exclusive choice that stays on the page. RadioGroup.Root owns the value, the shared name, disabled, and invalid. RadioGroup.Item cannot take checked or name. An item outside a root throws.
On this page
The group type requires aria-label or aria-labelledby. A role="radiogroup" div is not a labelable control, so do not point Label.Root htmlFor at the group. Caption it with Text.Root and aria-labelledby, and put both in a Field.Group to space the caption from the group.
value={null} is controlled with nothing selected. Omit value for uncontrolled.
import { Description, Field, RadioGroup, Text } from '@tounsoo/todae';
import { useId, useState } from 'react';
export default function RadioPlan() {
const captionId = useId();
const proHintId = useId();
const [plan, setPlan] = useState<string | null>('free');
return (
<Field.Group>
<Text.Root as="span" id={captionId} weight="medium">
Plan
</Text.Root>
<RadioGroup.Root aria-labelledby={captionId} value={plan} onValueChange={setPlan}>
<RadioGroup.Item value="free">Free</RadioGroup.Item>
<RadioGroup.Item value="pro" aria-describedby={proHintId}>
Pro
</RadioGroup.Item>
<RadioGroup.Item value="enterprise" disabled>
Enterprise
</RadioGroup.Item>
</RadioGroup.Root>
<Description.Root id={proHintId}>Pro adds seats and audit logs.</Description.Root>
</Field.Group>
);
}
The dot of the checked radio grows in over selection.motion.duration. When the user prefers reduced motion, it only fades.
onValueChange gets null when a form reset leaves no radio selected, so hold the value as string | null.
Same-name native radios move focus with arrow keys. The group does not add a keyboard handler.
Use Radio when the options stay visible. Use OptionList when the options live in a popover or sheet. Wiring both to the same value is a QA fail.
Accessible composition
Todae handles: RadioGroup.Root renders a div with role="radiogroup", aria-orientation, and aria-disabled and aria-invalid when they apply. Its type requires aria-label or aria-labelledby. Each RadioGroup.Item is a native radio inside a <label> with your children. The items share a name, generated when you pass none, so the browser gives the group one tab stop and the arrow keys described above. Items get native disabled and aria-invalid from the group, which also takes them from a surrounding Fieldset.
You supply: The group's name: a visible caption with an id in aria-labelledby, or aria-label. Children on every item. For an error, invalid and the ErrorMessage id in the root's aria-describedby. When you wrap the root, keep its props type whole so the name stays required:
type PlanPickerProps = RadioGroupRootProps & { plans: readonly string[] };
function PlanPicker({ plans, ...group }: PlanPickerProps) {
return (
<RadioGroup.Root {...group}>
{plans.map((plan) => (
<RadioGroup.Item key={plan} value={plan}>{plan}</RadioGroup.Item>
))}
</RadioGroup.Root>
);
}
Watch for: Omit<RadioGroupRootProps, …> turns the naming union into two optional props, so a wrapper built on it compiles without a name. Label.Root htmlFor does not name a radiogroup div. Two groups with the same name in one form are one set to the browser's arrow keys.
When to use
When: Exclusive choice that stays visible on the page. Group owns value/name; caption via aria-label / aria-labelledby.
When not: Independent toggles → Checkbox. Overlay list → OptionList. Same value also wired to OptionList (dual-wire = fail).
Props
| Name | Type | Description |
|---|---|---|
aria-label | string | Accessible name when no visible caption exists. Exactly one of aria-label or aria-labelledby. |
aria-labelledby | string | Id of the visible caption. Exactly one of aria-label or aria-labelledby. |
value | string | null | Controlled value. null is controlled with nothing selected. Omit for uncontrolled. |
defaultValue | string | null | Initial value when uncontrolled. |
onValueChange | (value: string | null) => void | Fires with the next selected value, or null when a form reset leaves no radio selected. |
name | string | Shared native name. Generated when omitted. |
disabled | boolean | Disables every radio. |
invalid | boolean | Marks every radio invalid. |
customValidity | string | A message for a rule the browser cannot check, set with setCustomValidity on the first radio that takes part in validation. An empty string or undefined means the rule holds. |
orientation | "vertical" | "horizontal" | Layout and aria-orientation. Default: "vertical" |
children | React.ReactNode | RadioGroup.Item children. |
className | string | Optional class on the radiogroup. |
| Name | Type | Description |
|---|---|---|
value Required | string | Option value. The group owns selection. |
children Required | React.ReactNode | Visible label. |
disabled | boolean | Disables this option. The group disabled flag also applies. |
className | string | Optional class on the wrapping label. |