Radix homepage
Components

Radio Group

A set of checkable buttons—known as radio buttons—where no more than one of the buttons can be checked at a time.

import React from 'react';
import * as RadioGroup from '@radix-ui/react-radio-group';
import './styles.css';
const RadioGroupDemo = () => (
<form>
<RadioGroup.Root className="RadioGroupRoot" defaultValue="default" aria-label="View density">
<div style={{ display: 'flex', alignItems: 'center' }}>
<RadioGroup.Item className="RadioGroupItem" value="default" id="r1">
<RadioGroup.Indicator className="RadioGroupIndicator" />
</RadioGroup.Item>
<label className="Label" htmlFor="r1">
Default
</label>
</div>
<div style={{ display: 'flex', alignItems: 'center' }}>
<RadioGroup.Item className="RadioGroupItem" value="comfortable" id="r2">
<RadioGroup.Indicator className="RadioGroupIndicator" />
</RadioGroup.Item>
<label className="Label" htmlFor="r2">
Comfortable
</label>
</div>
<div style={{ display: 'flex', alignItems: 'center' }}>
<RadioGroup.Item className="RadioGroupItem" value="compact" id="r3">
<RadioGroup.Indicator className="RadioGroupIndicator" />
</RadioGroup.Item>
<label className="Label" htmlFor="r3">
Compact
</label>
</div>
</RadioGroup.Root>
</form>
);
export default RadioGroupDemo;

Features

  • Full keyboard navigation.
  • Supports horizontal/vertical orientation.
  • Can be controlled or uncontrolled.

Install the component from your command line.

npm install @radix-ui/react-radio-group

Import all parts and piece them together.

import * as RadioGroup from '@radix-ui/react-radio-group';
export default () => (
<RadioGroup.Root>
<RadioGroup.Item>
<RadioGroup.Indicator />
</RadioGroup.Item>
</RadioGroup.Root>
);

Contains all the parts of a radio group.

PropTypeDefault
asChildbooleanfalse
defaultValuestringNo default value
valuestringNo default value
onValueChangefunctionNo default value
disabledbooleanNo default value
namestringNo default value
requiredbooleanNo default value
orientationenumundefined
direnumNo default value
loopbooleantrue
Data AttributeValues
[data-disabled]Present when disabled

An item in the group that can be checked. An input will also render when used within a form to ensure events propagate correctly.

PropTypeDefault
asChildbooleanfalse
valuestringNo default value
disabledbooleanNo default value
requiredbooleanNo default value
Data AttributeValues
[data-state]"checked" | "unchecked"
[data-disabled]Present when disabled

Renders when the radio item is in a checked state. You can style this element directly, or you can use it as a wrapper to put an icon into, or both.

PropTypeDefault
asChildbooleanfalse
forceMountbooleanNo default value
Data AttributeValues
[data-state]"checked" | "unchecked"
[data-disabled]Present when disabled

Adheres to the Radio Group WAI-ARIA design pattern and uses roving tabindex to manage focus movement among radio items.

KeyDescription
TabMoves focus to either the checked radio item or the first radio item in the group.
SpaceWhen focus is on an unchecked radio item, checks it.
ArrowDownMoves focus and checks the next radio item in the group.
ArrowRightMoves focus and checks the next radio item in the group.
ArrowUpMoves focus to the previous radio item in the group.
ArrowLeftMoves focus to the previous radio item in the group.