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.
Interactive Preview
Section titled “Interactive Preview”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> );}<script lang="ts"> import RadioGroup from "@/components/ui/radio-group.svelte"; import RadioGroupLabel from "@/components/ui/radio-group-label.svelte"; import RadioItem from "@/components/ui/radio-item.svelte"; import RadioItemControl from "@/components/ui/radio-item-control.svelte"; import RadioItemIndicator from "@/components/ui/radio-item-indicator.svelte"; import RadioItemText from "@/components/ui/radio-item-text.svelte";</script>
<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>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> );}Installation
Section titled “Installation”npx @glaceon/cli add radio-group --framework react # or svelte, solidInstall the Zag radio group state machine and framework adapter:
bun add @zag-js/radio-group @zag-js/react clsx tailwind-mergebun add @zag-js/radio-group @zag-js/svelte clsx tailwind-mergebun add @zag-js/radio-group @zag-js/solid clsx tailwind-mergeData Attributes
Section titled “Data Attributes”| 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.
API Reference (Props)
Section titled “API Reference (Props)”| 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().
Keyboard Interactions
Section titled “Keyboard Interactions”| 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 |
Accessibility
Section titled “Accessibility”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.