VayuUI

RadioGroup

A set of checkable buttons where no more than one can be checked at a time.

Installation

npx vayu-ui init #one time only
npx vayu-ui add radiogroup
npx vayu-ui add -t radiogroup #with test case needs

Usage

Basic Usage

Select a subscription plan with descriptions.

Choose the plan that fits your needs.

Horizontal Layout

Radio buttons arranged horizontally.

Select your preferred size.

Error State

Validation error with disabled option.

Select a priority level for your ticket.

<RadioGroup
  name="notifications"
  defaultValue="all"
  label="Notification Preferences"
  description="Choose what you want to be notified about"
>
  <RadioGroup.Item
    value="all"
    label="Everything"
    description="Get notified about all activities"
  />
  <RadioGroup.Item
    value="mentions"
    label="Mentions only"
    description="Only get notified when someone mentions you"
  />
  <RadioGroup.Item
    value="none"
    label="Nothing"
    description="Disable all notifications"
    disabled
  />
</RadioGroup>

Anatomy

import { RadioGroup } from 'vayu-ui';

<RadioGroup>
  <RadioGroup.Item value="item-1" />
</RadioGroup>;

Accessibility

  • Keyboard support: Use Tab to navigate to the radio group. Press Arrow keys to move between items and Space or Enter to select.
  • ARIA attributes: Uses role="radiogroup" for the container with aria-labelledby and aria-describedby for context. Utilizes hidden native input[type="radio"] for native semantics.
  • Focus behavior: Focus is visually represented on the custom indicator element while being managed natively by the hidden input element.

Screen reader behavior

Screen readers announce the group's label and description upon focusing. As the user navigates between options, the screen reader reads the individual item's label, its position in the set, and whether it is selected or disabled. Error states are announced dynamically using aria-live="polite".

Component Folder Structure

RadioGroup/
├── RadioGroup.tsx
├── RadioItem.tsx
├── hooks.ts
├── index.ts
└── types.ts

Props

RadioGroup

PropTypeDefaultDescription
valuestring-The controlled value of the radio group.
defaultValuestring""The initial value when uncontrolled.
onChange(value: string) => void-Event handler called when the value changes.
namestringauto-generatedThe name used for grouping the inputs.
disabledbooleanfalseWhen true, prevents interaction with all items.
orientation"vertical" | "horizontal""vertical"The visual orientation of the items.
labelstring-The label for the entire group.
descriptionstring-Descriptive text for the group.
errorbooleanfalseIndicates if the group has an error.
errorTextstring-The error message to display.
requiredbooleanfalseMarks the field as required.

RadioGroup.Item

PropTypeDefaultDescription
value*string-The unique value of the item in the group.
labelstring-The text label for the radio option.
descriptionstring-Additional descriptive subtext.
disabledbooleanfalseWhen true, disables the individual radio item.

On this page