RadioGroup
Features
- Full keyboard navigation.
- Supports horizontal/vertical orientation.
- Can be controlled or uncontrolled.
Installation
Install the component from your command line.
$ npm add reka-uiAnatomy
Import all parts and piece them together.
<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.
| Prop | Default | Type |
|---|---|---|
as | 'div' | AsTag | ComponentThe element or component this component should render as. Can be overwrite by |
asChild | booleanChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | |
defaultValue | AcceptableValueThe value of the radio item that should be checked when initially rendered. Use when you do not need to control the state of the radio items. | |
dir | 'ltr' | 'rtl'The reading direction of the combobox when applicable. | |
disabled | false | booleanWhen |
loop | true | booleanWhen |
modelValue | AcceptableValueThe controlled value of the radio item to check. Can be binded as | |
name | stringThe name of the field. Submitted with its owning form as part of a name/value pair. | |
orientation | 'vertical' | 'horizontal'The orientation of the component. | |
required | false | booleanWhen |
| Emit | Payload |
|---|---|
update:modelValue | [payload: string]Event handler called when the radio group value changes |
| Slots (default) | Payload |
|---|---|
modelValue | string | number | Record<string, any>Current input values |
| Data Attribute | Value |
|---|---|
[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.
| Prop | Default | Type |
|---|---|---|
as | 'button' | AsTag | ComponentThe element or component this component should render as. Can be overwrite by |
asChild | booleanChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | |
disabled | false | booleanWhen |
id | string | |
name | stringThe name of the field. Submitted with its owning form as part of a name/value pair. | |
required | booleanWhen | |
value | AcceptableValueThe value given as data when submitted with a |
| Emit | Payload |
|---|---|
select | [event: SelectEvent]Event handler called when the user selects a link (via mouse or keyboard). Calling |
| Data Attribute | Value |
|---|---|
[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.
| Prop | Default | Type |
|---|---|---|
as | 'span' | AsTag | ComponentThe element or component this component should render as. Can be overwrite by |
asChild | booleanChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | |
forceMount | booleanUsed to force mounting when more control is needed. Useful when controlling animation with Vue animation libraries. |
| Data Attribute | Value |
|---|---|
[data-state] | "checked" | "unchecked" |
[data-disabled] | Present when disabled |
Accessibility
Adheres to the Radio Group WAI-ARIA design pattern and uses roving tabindex to manage focus movement among radio items.
Keyboard Interactions
| Key | Description |
|---|---|
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. |
