Radio Group
Web/MobileA set of checkable buttons where only one can be checked at a time. Compose each option with Label via id and htmlFor.
Installation
pnpm dlx cubix-ui@latest add radio-groupUsage
import { Label } from "@/components/cubix/label"
import { RadioGroup, RadioGroupItem } from "@/components/cubix/radio-group"
<RadioGroup defaultValue="comfortable" aria-label="تراکم نمایش" className="w-fit">
<div className="flex items-center gap-2">
<RadioGroupItem id="radio-demo-default" value="default" />
<Label htmlFor="radio-demo-default">پیشفرض</Label>
</div>
<div className="flex items-center gap-2">
<RadioGroupItem id="radio-demo-comfortable" value="comfortable" />
<Label htmlFor="radio-demo-comfortable">راحت</Label>
</div>
<div className="flex items-center gap-2">
<RadioGroupItem id="radio-demo-compact" value="compact" />
<Label htmlFor="radio-demo-compact">فشرده</Label>
</div>
</RadioGroup>
Composition
RadioGroupItem is the control only. Pair each one with a Label using matching id and htmlFor. The group starts right-to-left and follows the closest dir on the page.
RadioGroup
└── div
├── RadioGroupItem (id, value)
└── Label (htmlFor)Accessibility
The group renders role="radiogroup"; name it with aria-label or point aria-labelledby at a visible heading. The group is a single tab stop, arrow keys move and select, and horizontal arrows follow the reading direction.
| Key | Action |
|---|---|
| Tab | Moves focus into the group onto the selected radio, or the first one when none is selected. |
| Space | Selects the focused radio when it is not selected yet. |
| ArrowDown / ArrowUp | Moves to and selects the next or previous enabled radio. |
| ArrowLeft / ArrowRight | Moves to and selects the next or previous enabled radio in reading direction, so the keys are mirrored in RTL. |
Examples
With description
Wrap each option in a bordered row and add a helper line under the label.
Horizontal
Lay the options out in a row with className="flex". In RTL the first option sits on the right and ArrowLeft moves to the next one.
Disabled
Set disabled on one radio to lock it, or on the group to lock every option. Arrow keys skip disabled radios.
Invalid
Set aria-invalid on the group and its items when a required choice is missing. The radios get a destructive border and ring; show the error copy below.
یک دوره پرداخت انتخاب کنید.
Form
Give the group a name so the selected value is submitted with the form.
API Reference
Note: Parts render data-slot attributes (radio-group, radio-group-item, radio-group-indicator) for targeting in tests and parent selectors. Use the same props on Base UI, React Aria, and Radix.
RadioGroup
| Prop | Type | Default | Description |
|---|---|---|---|
| value | string | - | Controlled selected value. Pair with onValueChange when the parent owns the value. |
| defaultValue | string | - | Initial selected value for uncontrolled usage. |
| onValueChange | (value: string) => void | - | Called with the next value whenever a radio is selected. |
| name | string | - | Shared name submitted with the form. Generated automatically when omitted. |
| disabled | boolean | false | Disables every radio in the group. |
| required | boolean | false | Marks the group as required for form validation. |
| aria-invalid | boolean | false | Marks the group as invalid. On React Aria it also paints every radio; set aria-invalid on each item for Base UI and Radix. |
| dir | "ltr" | "rtl" | closest dir on the page (rtl if none) | Reading direction. Sets which way ArrowLeft and ArrowRight move. |
| className | string | - | Additional Tailwind classes merged with the group styles (last one wins). |
RadioGroupItem
| Prop | Type | Default | Description |
|---|---|---|---|
| value | string | - | Value submitted when this radio is selected. Required. |
| id | string | - | Associates the control with a Label through htmlFor for accessible naming. |
| disabled | boolean | false | Disables this radio independently of the group. Arrow keys skip it. |
| aria-invalid | boolean | false | Adds a destructive border and ring. Show the error copy below the group. |
| className | string | - | Additional Tailwind classes merged onto the radio control (last one wins). |
States
| Prop | Type | Default | Description |
|---|---|---|---|
| checked | - | - | Primary fill with a filled indicator dot. |
| disabled | - | - | Unchecked stays full opacity; checked uses reduced opacity. |
| aria-invalid | - | - | Destructive border and ring. Show error copy below the group. |