Radio Group

A set of checkable buttons where only one can be checked at a time.

Installation

pnpm dlx cubix@latest add radio-group --base aria

Usage

Import
import { RadioGroup, RadioGroupItem } from "@/components/cubix/radio-group"
Example
<RadioGroup defaultValue="comfortable">
  <RadioGroupItem value="default">Default</RadioGroupItem>
  <RadioGroupItem value="comfortable">Comfortable</RadioGroupItem>
  <RadioGroupItem value="compact">Compact</RadioGroupItem>
</RadioGroup>

Examples

With description

Compose each radio with a title and supporting text for settings and plan pickers.

Disabled

Disable the whole group, or a single option.

Sizes

Horizontal

Set className="flex flex-row" to place options in a row.

API Reference

RadioGroup

The container that manages selection, the shared form name, and layout.

PropTypeDefaultDescription
valuestring-Controlled selected value. Use with `onValueChange`.
defaultValuestring-Initial selected value for uncontrolled usage.
onValueChange(value: string) => void-Called with the next value whenever a radio is selected.
namestring-Shared name submitted with the form. Generated automatically when omitted.
disabledbooleanfalseDisables every radio in the group.
requiredbooleanfalseMarks the group as required for native form validation.
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).
...propsReact.ComponentProps<'div'>-All native div attributes (id, aria-label, aria-labelledby, ...) are forwarded to the radiogroup.

RadioGroupItem

A single option. Must be rendered inside RadioGroup. Pass children to render a label, or compose your own.

PropTypeDefaultDescription
valuestring-Value submitted when this radio is selected. Required.
disabledbooleanfalseDisables this radio independently of the group.
aria-invalidbooleanfalseWhen true, indicates the radio is in an invalid state.
classNamestring-Additional Tailwind classes merged onto the radio wrapper (last one wins).
...propsReact.ComponentProps<'input'>-All native radio attributes (id, form, tabindex, aria-*, ...) are forwarded to the rendered input.

Variants

PropTypeDefaultDescription
default--Checked state with primary background and a filled indicator.
disabled--Disabled radios cannot be interacted with.