Radio
"use client";
import { Field, Radio, RadioGroup } from "@cherry-design-system/react";
export function Plan() {
return (
<Field label="Plan">
<RadioGroup name="plan" defaultValue="pro">
<Radio value="free" label="Free" />
<Radio value="pro" label="Pro" />
<Radio value="team" label="Team" />
</RadioGroup>
</Field>
);
}Radio is a native <input type="radio">; RadioGroup wraps a set of them (role="radiogroup") and hands each one its name, value, size and state. Use it for one choice out of a few visible options. Use Select when there are many options and ToggleGroup for a view switch outside a form.
Examples
Horizontal
"use client";
import { Field, Radio, RadioGroup } from "@cherry-design-system/react";
export function Billing() {
return (
<Field label="Billing period">
<RadioGroup name="billing" defaultValue="monthly" orientation="horizontal" size="sm">
<Radio value="monthly" label="Monthly" />
<Radio value="yearly" label="Yearly" />
</RadioGroup>
</Field>
);
}Controlled
"use client";
import { useState } from "react";
import { Field, Radio, RadioGroup } from "@cherry-design-system/react";
export function Shipping() {
const [method, setMethod] = useState<string | null>("standard");
return (
<Field label="Shipping">
<RadioGroup value={method} onValueChange={setMethod}>
<Radio value="standard" label="Standard (3 to 5 days)" />
<Radio value="express" label="Express (next day)" />
<Radio value="pickup" label="Pick up in store" disabled />
</RadioGroup>
</Field>
);
}Required and error
"use client";
import { Field, Radio, RadioGroup } from "@cherry-design-system/react";
export function Size() {
return (
<Field label="Size" required error="Pick a size.">
<RadioGroup name="size">
<Radio value="s" label="Small" />
<Radio value="m" label="Medium" />
<Radio value="l" label="Large" />
</RadioGroup>
</Field>
);
}Properties
RadioGroup
Shared input name. Generated when omitted.
Controlled selected value.
Initial value when uncontrolled. Defaults to null.
Called with the newly selected value.
Size passed to every Radio. Defaults to "md".
Stack direction. Defaults to "vertical".
Error state; set automatically inside a <Field error>.
Disables every option.
Marks the group as required.
Renders a <div>, forwards its ref and passes through native <div> attributes.
Radio
The value submitted, and matched against the group's value.
Visible label. Omit only when an aria-label is given.
16 / 18 / 20 px. Inherits the group's size.
Error state. Inherits the group's (or Field's) state.
Class for the outer <label> (className goes to the <input>).
The ref and native <input> attributes go to the <input>.
Styling
Radio root class cherry-radio and group class cherry-radio-group. data-size (sm, md, lg) and, on the group, data-orientation (vertical, horizontal). States: data-invalid, data-disabled, :checked, :disabled. Parts: cherry-radio__control, __input, __dot, __label.
Reads --cherry-primary-default for the checked state, --cherry-border-strong, --cherry-danger-solid, --cherry-ring and --cherry-ring-danger.
Accessibility
Native radios in a named radiogroup: arrow keys move and select. Name the group with a Field label (linked through aria-labelledby), aria-label or aria-labelledby.