Skip to main content

radio group

A set of checkable buttons -- known as radio buttons -- where no more than one of the buttons can be checked at a time.

Philosophy

Radio groups enforce single selection from a set — the constraint is the feature. Unlike checkboxes (multi-select) or selects (dropdown), radio groups make all options visible simultaneously. The primitive layer handles keyboard navigation (arrow keys plus Home/End/PageUp/PageDown navigation, auto-selecting on focus), form integration via hidden native radio inputs, and RTL direction support.

How It's Built

Loading diagram...

Installation


npx @gentleduck/cli add radio-group

npx @gentleduck/cli add radio-group

Usage

import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"
<RadioGroup defaultValue="option-one">
  <RadioGroupItem value="option-one">Option One</RadioGroupItem>
  <RadioGroupItem value="option-two">Option Two</RadioGroupItem>
</RadioGroup>
<RadioGroup defaultValue="option-one">
  <RadioGroupItem value="option-one">Option One</RadioGroupItem>
  <RadioGroupItem value="option-two">Option Two</RadioGroupItem>
</RadioGroup>

Examples

Form

Keyboard Navigation

KeyDescription
ArrowDownMove focus to next item and select it
ArrowRightMove focus to next item and select it
ArrowUpMove focus to previous item and select it
ArrowLeftMove focus to previous item and select it
HomeMove focus to first item and select it
EndMove focus to last item and select it
PageUpMove focus to first item and select it
PageDownMove focus to last item and select it
a-zJump to next item matching typed characters and select it
g gJump to first item and select it
GJump to last item and select it
TabMove focus into/out of the radio group
SpaceSelect the focused item (if not already selected)

Component Composition

Loading diagram...

API Reference

RadioGroup

PropTypeDefaultDescription
valuestring--Controlled value of the selected radio item
defaultValuestring--Initial selected value when uncontrolled
onValueChange(value: string) => void--Callback fired when selection changes
disabledbooleanfalseWhether the entire group is disabled
requiredbooleanfalseWhether the group is required in a form
namestring--The name used when submitting an HTML form
dir'ltr' | 'rtl'--Text direction. Resolved by primitives useDirection (dir prop -> DirectionProvider -> 'ltr').
orientation'horizontal' | 'vertical'--The orientation of the group for arrow key navigation
loopbooleantrueWhether keyboard navigation should loop
classNamestring--Additional CSS classes

RadioGroupItem

PropTypeDefaultDescription
valuestring(required)Unique value for the radio item
disabledbooleanfalseWhether this item is disabled
indicatorReact.ReactElement--Custom SVG or element for unchecked state indicator
checkedIndicatorReact.ReactElement--Custom SVG or element for checked state indicator
textValuestring--Optional text used for keyboard typeahead matching (a-z). In the registry component, plain string/number children are inferred automatically.
childrenReact.ReactNode--Label content. When provided, a clickable label is rendered next to the control and selects the item on click.
classNamestring--Additional CSS classes for the radio button control

RTL Support

Set dir="rtl" on RadioGroup for a local override, or set DirectionProvider once at app/root level for global direction.

See also