import { RadioGroup } from "@senvenli/react/selection";
export default function Example() {
return (
<RadioGroup
label="Billing period"
defaultValue="yearly"
items={[
{ value: "monthly", label: "Monthly" },
{ value: "yearly", label: "Yearly", description: "Two months free." },
]}
/>
);
}import { RadioGroup, Radio } from "@senvenli/react/selection";Examples
With descriptions
Radio children, each with a line of detail; one is unavailable.import { Radio, RadioGroup } from "@senvenli/react/selection";
export default function Example() {
return (
<RadioGroup label="Delivery" description="Applies to every order in this shipment." defaultValue="standard">
<Radio value="standard" description="3–5 business days, free.">
Standard
</Radio>
<Radio value="express" description="Next business day, $12.">
Express
</Radio>
<Radio value="pickup" description="Not available for this address." isDisabled>
Store pickup
</Radio>
</RadioGroup>
);
}Horizontal
Short options on one line; they wrap when space runs out.import { RadioGroup } from "@senvenli/react/selection";
import { useState } from "react";
export default function Example() {
const [priority, setPriority] = useState("normal");
return (
<RadioGroup
label="Priority"
description={`Saved as “${priority}”.`}
orientation="horizontal"
value={priority}
onChange={setPriority}
items={[
{ value: "low", label: "Low" },
{ value: "normal", label: "Normal" },
{ value: "high", label: "High" },
]}
/>
);
}Cards
`variant="card"`: each option a card, its content yours (a name, a Badge, a price).import { Badge, Text } from "@senvenli/react/display";
import { Stack } from "@senvenli/react/layout";
import { Radio, RadioGroup } from "@senvenli/react/selection";
// A card's content is yours: here a name with a "Recommended" Badge, a line of detail and a price.
export default function Example() {
return (
<RadioGroup label="Plan" variant="card" defaultValue="team">
<Radio value="starter" description="For one person.">
<Stack as="span" space="space-050">
<span>Starter</span>
<Text size="body-large" weight="medium" isNumeric>$0</Text>
</Stack>
</Radio>
<Radio value="team" description="Up to 20 people.">
<Stack as="span" space="space-050">
<Stack direction="horizontal" as="span" space="space-075" align="center">
<span>Team</span>
<Badge tone="brand">Recommended</Badge>
</Stack>
<Text size="body-large" weight="medium" isNumeric>$12 / month</Text>
</Stack>
</Radio>
<Radio value="business" description="Audit log and single sign-on.">
<Stack as="span" space="space-050">
<span>Business</span>
<Text size="body-large" weight="medium" isNumeric>$29 / month</Text>
</Stack>
</Radio>
</RadioGroup>
);
}Time slots
Cards as a time picker; a taken time stays visible, disabled, with its reason.import { RadioGroup } from "@senvenli/react/selection";
// A time-slot picker is a card group: one time per card; a taken time stays visible, disabled, and says so.
const TIMES = ["9:00", "9:30", "10:00", "10:30", "11:00", "11:30"];
const TAKEN = new Set(["9:30", "11:00"]);
export default function Example() {
return (
<RadioGroup
label="Available times · March 18"
variant="card"
defaultValue="10:30"
items={TIMES.map((time) => ({ value: time, label: time, description: TAKEN.has(time) ? "Taken" : undefined, isDisabled: TAKEN.has(time) }))}
/>
);
}Guidelines
When to use it
- One choice from 2 to 5 options people should compare.
Use something else when
Do and avoid
- Use variant="card" when each option needs a line of detail (a plan, a delivery option, a time slot); its content is yours.
Accessibility
Keyboard
| Keys | What happens |
|---|---|
| Arrow keys | Moves and selects within the group. |
Built in
- One tab stop for the group.
- Required fields show "Fill in this field." after a blur or a submit; your own
errorMessagereplaces it.
You provide
- A label for the group.
API reference
RadioGroup
| Prop | Type | Default | Description |
|---|---|---|---|
size | ComponentSize | – | The size of every Radio in the group. |
labelRequired | React.ReactNode | – | The group legend, required. |
items | readonly RadioItem[] | – | The options as data, or |
children | React.ReactNode | – | |
description | React.ReactNode | – | |
errorMessage | React.ReactNode | – | |
requiredValidation | RequiredValidation | – | Who says a required group with no option chosen is missing: |
variant | RadioGroupVariant | "default" |
|
sizeComponentSizeThe size of every Radio in the group.
labelRequiredReact.ReactNodeThe group legend, required.
itemsreadonly RadioItem[]The options as data, or
Radiochildren.childrenReact.ReactNodedescriptionReact.ReactNodeerrorMessageReact.ReactNoderequiredValidationRequiredValidationWho says a required group with no option chosen is missing:
field(default) shows "Fill in this field." when focus leaves the group and on a DS Form submit, which it then blocks;apponly marks the group. See {@link RequiredValidation}. The app'sisInvalid(truewith itserrorMessage, orfalse) overrides the check, as on TextField. Disabled, empty and required, it still blocks a DS Form's submit and cannot take focus (as TextField).variantRadioGroupVariantDefault"default"default: rows with a dot.card: each option a card in a grid of equal columns (no narrower than 180px), for choices that need a line of detail each (a plan, a delivery option, a time slot).
Radio
| Prop | Type | Default | Description |
|---|---|---|---|
valueRequired | string | – | |
size | ComponentSize | – |
|
childrenRequired | React.ReactNode | – | |
description | React.ReactNode | – | |
isDisabled | boolean | – |
valueRequiredstringsizeComponentSizesmall,medium(default) orlarge; a group's size, then the provider default, otherwise.childrenRequiredReact.ReactNodedescriptionReact.ReactNodeisDisabledboolean