Mutually exclusive radio buttons
import {Radio, RadioGroup} from "@peakui/react";
A radio button renders only inside a group — the parts document their anatomy here.
<RadioGroup>
<Label>Label</Label>
<Radio value="a">
<Radio.Content>
<Radio.Control>
<Radio.Indicator />
</Radio.Control>
Option A
</Radio.Content>
<Description>Optional description</Description>
</Radio>
</RadioGroup>
<RadioGroup className="gap-2">
<Label>Label</Label>
<Radio value="a">
<Radio.Content>
<Radio.Control>
<Radio.Indicator />
</Radio.Control>
Option A
</Radio.Content>
</Radio>
</RadioGroup>
.radio-group {
--radio-control-bg: var(--default);
}
| Class | Description |
|---|
.radio-group | The group wrapper element |
.radio-group--primary, .radio-group--secondary | Variant modifiers |
.radio | The radio field wrapper |
.radio__content | The clickable label wrapping control and text |
.radio__control | The circle the indicator sits in |
.radio__indicator | The indicator container |
| Slot | Description |
|---|
[data-slot="radio-group"] | The group wrapper element |
[data-slot="radio"] | The radio field wrapper |
[data-slot="radio-content"] | The clickable label element |
[data-slot="radio-control"] | The circle element |
[data-slot="radio-indicator"] | The indicator container element |
| Variable | Purpose |
|---|
--radio-control-bg | Unselected background of the secondary variant control |
--radio-control-bg-hover | Hover background of the secondary variant control |
The component supports both CSS pseudo-classes and data attributes:
| State | Attribute |
|---|
| Selected | [data-selected="true"] |
| Hovered | [data-hovered="true"] |
| Pressed | [data-pressed="true"] |
| Focused (visible) | [data-focus-visible="true"] |
| Disabled | [data-disabled="true"] |
| Invalid | [data-invalid="true"] |
| Prop | Type | Default | Description |
|---|
variant | "primary" | "secondary" | "primary" | Visual variant of the group wrapper |
value | string | - | Controlled selected value |
defaultValue | string | - | Uncontrolled initial value |
orientation | "horizontal" | "vertical" | "vertical" | Layout direction |
isDisabled | boolean | - | Disables every child radio |
isReadOnly | boolean | - | Makes every child radio read-only |
name | string | - | The name used when submitting an HTML form |
onChange | (value: string) => void | - | Called when the selection changes |
render | DOMRenderFunction<'div', RadioGroupRenderProps> | - | Replaces the rendered element |
...rest | | | Every React Aria RadioGroup attribute is accepted |
| Prop | Type | Default | Description |
|---|
value | string | - | The value this radio represents in the group |
isDisabled | boolean | - | Disables this radio |
isInvalid | boolean | - | Marks this radio invalid |
isRequired | boolean | - | Marks this radio required |
render | DOMRenderFunction<'div', RadioFieldRenderProps> | - | Replaces the rendered element |
...rest | | | Every React Aria RadioField attribute is accepted |
| Prop | Type | Default | Description |
|---|
render | DOMRenderFunction<'label', RadioButtonRenderProps> | - | Replaces the rendered label element |
...rest | | | Every React Aria RadioButton attribute is accepted |
| Prop | Type | Default | Description |
|---|
render | DOMRenderFunction<'span', undefined> | - | Replaces the rendered element |
| Prop | Type | Default | Description |
|---|
children | ReactNode | ((state) => ReactNode) | - | Custom indicator; receives the field render props |
render | DOMRenderFunction<'span', undefined> | - | Replaces the rendered element |
children and className of RadioGroup.Root, Radio.Root and Radio.Content accept a function receiving the respective React Aria render props.