Radio Component

A radio group component built on top of Radix UI's Radio Group, providing a set of checkable buttons where only one can be checked at a time.

  • Follows WAI-ARIA patterns for accessibility
  • Keyboard navigation support
  • Customizable styles through className prop
  • Integrates seamlessly with form libraries

Installation

The Radio component is part of our UI library. You can import it directly from the components directory.


Usage

Here is how to use the radio group in your project.

React TSX
1import { RadioGroup, RadioGroupItem } from "@/components/modern-ui/radio"

React TSX
1<RadioGroup defaultValue="option-one">
2  <div className="flex items-center space-x-2">
3    <RadioGroupItem value="option-one" id="option-one" />
4    <label htmlFor="option-one">Option One</label>
5  </div>
6</RadioGroup>

Examples

Basic Radio Group

Disabled Radio Group

Form Integration


API Reference

RadioGroup

The root component that contains all radio items.

PropTypeDefaultDescription
defaultValuestring-The value of the radio item that should be checked by default
valuestring-The controlled value of the radio item to check
onValueChange(value: string) => void-Event handler called when the value changes
disabledbooleanfalseWhen true, prevents the user from interacting with the radio items
namestring-The name of the group. Submitted with its owning form as part of a name/value pair
requiredbooleanfalseWhen true, indicates that the user must check a radio item before the owning form can be submitted
orientation"horizontal" | "vertical""vertical"The orientation of the component
dir"ltr" | "rtl"-The reading direction of the radio group
loopbooleantrueWhen true, keyboard navigation will loop from last item to first and vice versa
classNamestring-Additional CSS classes for styling

RadioGroupItem

An individual radio item.

PropTypeDefaultDescription
valuestringRequiredThe unique value of the radio item
disabledbooleanfalseWhen true, prevents the user from interacting with the radio item
requiredbooleanfalseWhen true, indicates that the user must check the radio item before the owning form can be submitted
idstring-The ID of the radio item. Should be used with a label
classNamestring-Additional CSS classes for styling

Accessibility

The RadioGroup component follows the WAI-ARIA design pattern for Radio Groups.

Keyboard Interactions

KeyDescription
SpaceWhen focus is on a radio item, selects it
ArrowDownMoves focus to the next radio item in the group
ArrowRightMoves focus to 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