Skip to content

Search is only available in production builds. Try building and previewing the site to test it out locally.

Radio Group

A radio group lets the user pick exactly one option from a set. Arrow keys move between items and select as they go, which is the behaviour expected of a native radio group.

The component is composed from parts across two levels of context: <RadioGroup> owns the state machine, and each <RadioItem> publishes its own value so child parts can address the right item without repeating value on every part.

React Radio Grouplive
import {
RadioGroup, RadioGroupLabel, RadioItem, RadioItemControl, RadioItemIndicator, RadioItemText,
} from "@/components/ui/radio-group";
export function PlanSelector() {
return (
<RadioGroup defaultValue="monthly">
<RadioGroupLabel>Billing cycle</RadioGroupLabel>
<RadioItem value="monthly">
<RadioItemControl>
<RadioItemIndicator />
</RadioItemControl>
<RadioItemText>Monthly billing</RadioItemText>
</RadioItem>
<RadioItem value="annual">
<RadioItemControl>
<RadioItemIndicator />
</RadioItemControl>
<RadioItemText>Annual billing</RadioItemText>
</RadioItem>
</RadioGroup>
);
}
Terminal window
npx @glaceon/cli add radio-group --framework react # or svelte, solid
Attribute Values Applied to
data-scope radio-group every part
data-part root, label, item, item-control, item-text, item-hidden-input matching part
data-state checked, unchecked item control
data-disabled present / absent root, label, item

Zag’s getIndicatorProps() on this machine drives a single sliding indicator for the segmented-control pattern. A classic per-item dot is not that, so RadioItemIndicator here is purely presentational and is shown off the control’s data-state via a group class. Do not attach getIndicatorProps() to it: the dot would disappear.

The hidden input is rendered inside RadioItem rather than exposed as its own part, so it cannot be forgotten. It is what submits the selected value with the form.

Part Prop Type Description
RadioGroup children content The label and the items
RadioGroup defaultValue string Initially selected value
RadioGroup value string Controlled selected value
RadioGroup disabled boolean Disables the whole group
RadioGroup name string Name used in form submission
RadioGroup onValueChange (details) => void Called when the selection changes
RadioItem value string Required. The value this item represents
RadioItem disabled boolean Disables this item only
RadioItemText children content The visible label for the item

Every part also accepts className (React) or class (Svelte, Solid), merged with cn().

Key Behaviour
Arrow Down / Arrow Right Moves selection to the next radio item
Arrow Up / Arrow Left Moves selection to the previous radio item
Space Selects the focused radio item if not already selected

role="radiogroup" and role="radio" with aria-checked are managed by the Zag.js machine. The root is a <label> wrapping the control, giving each row a 44px tap target (WCAG 2.2 SC 2.5.8). Focus rings use the --action token at 2px.