Radio Group
Use RadioGroup when exactly one option should be selected from a small, visible set.
Preview
Display density
Choose compact, comfortable, or spacious density from three labeled options with supporting descriptions.
Installation
New to this Registry? Complete the base setup before continuing.
npx shadcn@latest add @neumorphism-ui/radio-groupInstall the shared base once, then add components and their dependencies with the CLI.
Display density
npx shadcn@latest add @neumorphism-ui/label @neumorphism-ui/radio-groupUsage
Give the group an accessible name and each RadioGroupItem a unique value and visible label. Set defaultValue or control the selected value with onValueChange.
"use client";
import { useId } from "react";
import { Label } from "@/components/ui/label";
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group";
export default function Example() {
const id = useId();
return (
<RadioGroup defaultValue="standard" aria-label="Delivery method">
<Label htmlFor={id + "-standard"} className="flex items-center gap-2">
<RadioGroupItem id={id + "-standard"} value="standard" />Standard
</Label>
<Label htmlFor={id + "-express"} className="flex items-center gap-2">
<RadioGroupItem id={id + "-express"} value="express" />Express
</Label>
</RadioGroup>
);
}API Reference
Shares the name and selected state through React context while rendering every item as a real input[type=radio]. Supports controlled and uncontrolled values, horizontal or vertical layout, disabled, and required.
| Component | Prop | Type | Default | Description |
|---|---|---|---|---|
RadioGroup | value / defaultValue | string | — | The controlled selected value or initial uncontrolled value. |
RadioGroup | onValueChange | (value: string) => void | — | Called when the selected value changes. |
RadioGroup | orientation | "horizontal" | "vertical" | "vertical" | Sets the layout direction and aria-orientation. |
RadioGroup | name | string | generated id | The native radio name shared by all items. |
RadioGroup | disabled / required | boolean | false | Sets input constraints for all items. |
RadioGroupItem | valuerequired | string | — | The value passed to the group when the item is selected. |
Accessibility
- 01
Give the RadioGroup root an accessible group name with aria-label or aria-labelledby.
- 02
Connect each RadioGroupItem id to Label htmlFor.
- 03
Real radio inputs preserve native form submission and keyboard selection behavior.