Reka UI logoReka
backdrop
Components

RadioGroup

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

Features

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

Installation

Install the component from your command line.

sh
$ npm add reka-ui

Anatomy

Import all parts and piece them together.

vue
<script setup>
import { RadioGroupIndicator, RadioGroupItem, RadioGroupRoot } from 'reka-ui'
</script>

<template>
  <RadioGroupRoot>
    <RadioGroupItem>
      <RadioGroupIndicator />
    </RadioGroupItem>
  </RadioGroupRoot>
</template>

API Reference

Root

Contains all the parts of a radio group.

Data AttributeValue
[data-disabled]Present when disabled

Item

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

Data AttributeValue
[data-state]"checked" | "unchecked"
[data-disabled]Present when disabled

Indicator

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.

tip
Built with Presence component - supports any animation techniques while maintaining access to presence emitted events.
Data AttributeValue
[data-state]"checked" | "unchecked"
[data-disabled]Present when disabled

Examples

Card options

Render anything inside a RadioGroupItem: it is the radio, so its text becomes its accessible name and the whole card is clickable. Style the selected card with [data-state=checked] and a disabled one with [data-disabled].

Plan

Selected: pro

Orientation and direction

Without orientation, all four arrow keys move between the items. Set orientation="horizontal" to use only Left and Right (or vertical for Up and Down), so the other keys stay free, for example for scrolling. In a right-to-left layout, set dir="rtl" (or wrap the app in a ConfigProvider) so Left and Right follow the reading direction. Set :loop="false" to stop at the first and last item.

vue
<template>
  <RadioGroupRoot
    v-model="alignment"
    orientation="horizontal"
    dir="rtl"
    :loop="false"
  >
    <!-- ... -->
  </RadioGroupRoot>
</template>

In a form

With a name, each item inside a form renders a hidden native radio, so the browser submits the selected value. Inside a FieldRoot, the group takes the field's name, required and disabled, FieldLabel labels it, and an invalid submission focuses the selected item (or the first enabled one). Outside a field, label it with aria-labelledby (or aria-label). See Forms and validation.

vue
<template>
  <form @submit.prevent="onSubmit">
    <span id="shipping-label">Shipping</span>
    <RadioGroupRoot
      name="shipping"
      default-value="standard"
      aria-labelledby="shipping-label"
    >
      <RadioGroupItem value="standard" aria-label="Standard" />
      <RadioGroupItem value="express" aria-label="Express" />
    </RadioGroupRoot>
    <button type="submit">
      Continue
    </button>
  </form>
</template>

Reacting to changes

update:modelValue receives a second argument with the reason ('item-press', also for arrow-key selection, or 'imperative-action') and the native event. beforeUpdate:modelValue fires first; call details.cancel() to keep the current value.

vue
<template>
  <RadioGroupRoot
    v-model="plan"
    @before-update:model-value="(value, details) => {
      if (value === 'free' && hasPaidFeatures)
        details.cancel()
    }"
  >
    <!-- ... -->
  </RadioGroupRoot>
</template>

Accessibility

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

Keyboard Interactions

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.

Headless composable

useRadioGroup holds the selected value (modelValue, selectValue()), the root part surface and getItemSurface(value, disabled?), which returns the surface of one radio: role="radio", aria-checked, data-state and the press handler. Arrow-key navigation between the radios is not part of it: render the items in a RovingFocusGroup, or use the components. The composable is experimental; see Headless composables.