PeakUI

RadioGroup

Mutually exclusive radio buttons

Usage

import {Radio, RadioGroup} from "@peakui/react";

A radio button renders only inside a group — the parts document their anatomy here.

Anatomy

<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>

Examples

Orientation

Disabled

Controlled

Customization

Tailwind CSS

<RadioGroup className="gap-2">
  <Label>Label</Label>
  <Radio value="a">
    <Radio.Content>
      <Radio.Control>
        <Radio.Indicator />
      </Radio.Control>
      Option A
    </Radio.Content>
  </Radio>
</RadioGroup>

Global CSS

.radio-group {
  --radio-control-bg: var(--default);
}

Styling Reference

CSS Classes

ClassDescription
.radio-groupThe group wrapper element
.radio-group--primary, .radio-group--secondaryVariant modifiers
.radioThe radio field wrapper
.radio__contentThe clickable label wrapping control and text
.radio__controlThe circle the indicator sits in
.radio__indicatorThe indicator container

Slots

SlotDescription
[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

CSS Variables

VariablePurpose
--radio-control-bgUnselected background of the secondary variant control
--radio-control-bg-hoverHover background of the secondary variant control

Interactive States

The component supports both CSS pseudo-classes and data attributes:

StateAttribute
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"]

API Reference

RadioGroup.Root

PropTypeDefaultDescription
variant"primary" | "secondary""primary"Visual variant of the group wrapper
valuestring-Controlled selected value
defaultValuestring-Uncontrolled initial value
orientation"horizontal" | "vertical""vertical"Layout direction
isDisabledboolean-Disables every child radio
isReadOnlyboolean-Makes every child radio read-only
namestring-The name used when submitting an HTML form
onChange(value: string) => void-Called when the selection changes
renderDOMRenderFunction<'div', RadioGroupRenderProps>-Replaces the rendered element
...restEvery React Aria RadioGroup attribute is accepted

Radio.Root

PropTypeDefaultDescription
valuestring-The value this radio represents in the group
isDisabledboolean-Disables this radio
isInvalidboolean-Marks this radio invalid
isRequiredboolean-Marks this radio required
renderDOMRenderFunction<'div', RadioFieldRenderProps>-Replaces the rendered element
...restEvery React Aria RadioField attribute is accepted

Radio.Content

PropTypeDefaultDescription
renderDOMRenderFunction<'label', RadioButtonRenderProps>-Replaces the rendered label element
...restEvery React Aria RadioButton attribute is accepted

Radio.Control

PropTypeDefaultDescription
renderDOMRenderFunction<'span', undefined>-Replaces the rendered element

Radio.Indicator

PropTypeDefaultDescription
childrenReactNode | ((state) => ReactNode)-Custom indicator; receives the field render props
renderDOMRenderFunction<'span', undefined>-Replaces the rendered element

Render Props

children and className of RadioGroup.Root, Radio.Root and Radio.Content accept a function receiving the respective React Aria render props.

On this page