GitHub

Radio Group

Single-choice selection pattern for plans, preferences, and mutually exclusive options with accessible radio semantics and keyboard-friendly structure.

AccessibleDark ModeKeyboard Nav

Install

$npx react-principles add radio-group

Selected plan: pro

02

Code Snippet

src/ui/RadioGroup.tsx
import { RadioGroup } from "@/ui/RadioGroup";

<RadioGroup value={plan} onValueChange={setPlan}>
  <RadioGroup.Item value="starter" label="Starter" description="Best for side projects" />
  <RadioGroup.Item value="pro" label="Pro" description="For production apps" />
  <RadioGroup.Item value="enterprise" label="Enterprise" description="Advanced controls" />
</RadioGroup>
03

Copy-Paste (Single File)

RadioGroup.tsx
import { createContext, useContext, useId, useState, type HTMLAttributes, type ReactNode } from "react";
import { cn } from "@/lib/utils";

export interface RadioGroupProps extends HTMLAttributes<HTMLDivElement> {
  value?: string;
  defaultValue?: string;
  onValueChange?: (value: string) => void;
  name?: string;
  children: ReactNode;
}
04

Props

PropTypeDefaultDescription
valuestringControlled selected value for the root radio group.
defaultValuestring""Initial selected value when the group is uncontrolled.
onValueChange(value: string) => voidCalled when users pick a different radio option.
namestringGenerated idSets the shared hidden input name for the group.
RadioGroup.Item.valuestringUnique item value submitted when the option is selected.
RadioGroup.Item.disabledbooleanfalseDisables an individual option and prevents interaction.
RadioGroup.Item.labelstringPrimary label text rendered inside the option card.
RadioGroup.Item.descriptionstringSecondary helper text rendered below the label.
react-principles