Radio Group

Allows single selection from multiple options.

Loading...

Anatomy

<RadioGroup.Root>
  <RadioGroup.Label />
  <RadioGroup.Indicator />
  <RadioGroup.Item>
    <RadioGroup.ItemControl />
    <RadioGroup.ItemText />
    <RadioGroup.ItemHiddenInput />
  </RadioGroup.Item>
</RadioGroup.Root>

Examples

Initial Value

Set defaultValue to the value of the item selected initially.

Controlled

Use value and onValueChange to control the selected value.

Root Provider

Use RootProvider with the useRadioGroup hook to access the state and methods from outside the component.

Disabled

Set disabled to true to disable the group.

Guides

asChild

RadioGroup.Item renders a label by default, since radio inputs need labels for form semantics and accessibility.

With asChild, you must render a label element as the direct child of RadioGroup.Item.

// INCORRECT usage ❌
<RadioGroup.Item asChild>
  <div>
    <RadioGroup.ItemHiddenInput />
    <RadioGroup.ItemText>
      <RadioGroup.ItemControl />
    </RadioGroup.ItemText>
  </div>
</RadioGroup.Item>

// CORRECT usage ✅
<RadioGroup.Item asChild>
  <label>
    <RadioGroup.ItemHiddenInput />
    <RadioGroup.ItemText>
      <RadioGroup.ItemControl />
    </RadioGroup.ItemText>
  </label>
</RadioGroup.Item>

Hidden Input

RadioGroup.ItemHiddenInput renders a hidden native input. The radio group needs it for form submission, form libraries, validation and native form reset.

// INCORRECT usage ❌
<RadioGroup.Item>
  <RadioGroup.ItemText>
    <RadioGroup.ItemControl />
  </RadioGroup.ItemText>
</RadioGroup.Item>

// CORRECT usage ✅
<RadioGroup.Item>
  <RadioGroup.ItemHiddenInput />
  <RadioGroup.ItemText>
    <RadioGroup.ItemControl />
  </RadioGroup.ItemText>
</RadioGroup.Item>

API Reference

Props

Root

Defines the <div> element.

AttributeDefaultType
asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

For more details, read our Composition guide.
defaultValue
string

The initial value of the checked radio when rendered. Use when you don't need to control the value of the radio group.

disabled
boolean

If `true`, the radio group will be disabled

form
string

The associate form of the underlying input.

id
string

The unique identifier of the machine.

ids
ElementIds

The ids of the elements in the radio. Useful for composition.

invalid
boolean

If `true`, the radio group is marked as invalid.

name
string

The name of the input fields in the radio (Useful for form submission).

onValueChange
(details: ValueChangeDetails) => void

Function called once a radio is checked

orientation
'horizontal' | 'vertical'

Orientation of the radio group

readOnly
boolean

Whether the radio group is read-only

render
ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<RadioGroupRootState>

Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state.

required
boolean

If `true`, the radio group is marked as required.

value
string

The controlled value of the radio group

AttributeDescription
[data-radio-group-root]<uid>
[data-orientation]The orientation of the radio-group
[data-disabled]Present when disabled
[data-invalid]Present when invalid
[data-required]Present when required

Indicator

Defines the <div> element.

AttributeDefaultType
asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

For more details, read our Composition guide.
render
ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>

Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state.

AttributeDescription
[data-radio-group-indicator]<uid>
[data-disabled]Present when disabled
[data-orientation]The orientation of the indicator
[data-instant]
CSS VariableDescription
--leftThe left position value
--topThe top position value
--widthThe width of the element
--heightThe height of the element

ItemControl

Defines the <span> element.

AttributeDefaultType
asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

For more details, read our Composition guide.
render
ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>

Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state.

AttributeDescription
[data-radio-group-item-control]<uid>
[data-active]Present when active or pressed
[data-focus]Present when focused
[data-focus-visible]Present when focused with keyboard
[data-disabled]Present when disabled
[data-readonly]Present when read-only
[data-state]"checked" | "unchecked"
[data-hover]Present when hovered
[data-invalid]Present when invalid
[data-orientation]The orientation of the item
[data-indicator-pending]Present while the indicator isn't in place yet (server render or not measured)

ItemHiddenInput

Defines the <input> element.

AttributeDefaultType
asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

For more details, read our Composition guide.
render
ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>

Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state.

Item

Defines the <label> element.

AttributeDefaultType
value
string

asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

For more details, read our Composition guide.
disabled
boolean

invalid
boolean

render
ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<RadioGroupItemState>

Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state.

AttributeDescription
[data-radio-group-item]<uid>
[data-focus]Present when focused
[data-focus-visible]Present when focused with keyboard
[data-disabled]Present when disabled
[data-readonly]Present when read-only
[data-state]"checked" | "unchecked"
[data-hover]Present when hovered
[data-invalid]Present when invalid
[data-orientation]The orientation of the item
[data-indicator-pending]Present while the indicator isn't in place yet (server render or not measured)

ItemText

Defines the <span> element.

AttributeDefaultType
asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

For more details, read our Composition guide.
render
ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>

Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state.

AttributeDescription
[data-radio-group-item-text]<uid>
[data-focus]Present when focused
[data-focus-visible]Present when focused with keyboard
[data-disabled]Present when disabled
[data-readonly]Present when read-only
[data-state]"checked" | "unchecked"
[data-hover]Present when hovered
[data-invalid]Present when invalid
[data-orientation]The orientation of the item
[data-indicator-pending]Present while the indicator isn't in place yet (server render or not measured)

Label

Defines the <span> element.

AttributeDefaultType
asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

For more details, read our Composition guide.
render
ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>

Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state.

AttributeDescription
[data-radio-group-label]<uid>
[data-orientation]The orientation of the label
[data-disabled]Present when disabled
[data-invalid]Present when invalid
[data-required]Present when required

RootProvider

Defines the <div> element.

AttributeDefaultType
value
UseRadioGroupReturn

asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

For more details, read our Composition guide.
render
type ONLY_FOR_FORMAT = ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<RadioGroupRootProviderState>

Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state.

Context

API

PropertyType
value
string | null

The current value of the radio group

setValue
(value: string) => void

Function to set the value of the radio group

clearValue
VoidFunction

Function to clear the value of the radio group

focus
VoidFunction

Function to focus the radio group

getItemState
(props: ItemProps) => ItemState

Returns the state details of a radio input

getRootState
() => RootState

Returns the state of the radio group

Accessibility

Complies with the Radio WAI-ARIA design pattern.

Keyboard Support

KeyDescription
Tab
Moves focus to either the checked radio item or the first radio item in the group.
Space
When focus is on an unchecked radio item, checks it.
ArrowDown
Moves focus and checks the next radio item in the group.
ArrowRight
Moves focus and checks the next radio item in the group.
ArrowUp
Moves focus to the previous radio item in the group.
ArrowLeft
Moves focus to the previous radio item in the group.