oakoss/ui
Components

Radio Group

A set of options where only one can be chosen.

SourceReact Aria
Density

Installation

npx shadcn@latest add @oakoss/radio-group

Usage

import { RadioGroup, RadioGroupItem } from '#/components/ui/inputs/radio-group';

<RadioGroup label="Plan">
  <RadioGroupItem value="free">Free</RadioGroupItem>
  <RadioGroupItem description="Up to 20 seats." value="team">
    Team
  </RadioGroupItem>
</RadioGroup>;

Examples

Horizontal

orientation="horizontal" lays the options out in a row, and the arrow keys follow it.

BillingYearly saves two months.

Cards

variant="card" makes each option a card, with its description under the title; anywhere on a card selects it.

Plan
One project, community support.
Up to 20 seats and shared folders.
Single sign-on and audit logs.

Accessibility

React Aria renders a radiogroup named by label, with a native radio for each option inside a <label>, so an option's label is its name and its click target.

  • Keys: Tab moves to the selected option, or the first one if none is selected, and the arrow keys move the selection. In a horizontal group right to left, Left and Right follow the reading direction.
  • Description and errors: the group's description and error describe the group and each of its options, so screen readers repeat them on every option; an option's own description describes that option alone. None need ids. The error shows only while the group is invalid.
  • Required: the asterisk after a required group's label is hidden from screen readers, which hear the group's own required state. Chrome reports each option as invalid until one is chosen, as it does for any native required radio; validationBehavior="aria" avoids that, but then the group no longer blocks a native form submit.
  • Cards: the option's label stretches over its card, so the name stays the title, and the card shows focus and selection. A link or button in a card's description sits above the label, so it stays clickable.
  • Target size: each dot's hit area grows to 44px, and options sit far enough apart, stacked or in a row, that a dot's area never covers a neighbor. Set targetSize={false} for tighter options; the row stays at least 24px tall.
  • Contrast: a dot's border reaches 3:1 against the page, and a selected dot is a thick ring. In Windows High Contrast the dots and a selected card take system colors, so the selected option stays visible.

API

RadioGroup

Renders React Aria's RadioGroup. Children are its options.

Props

Prop

Type

Also accepts React Aria RadioGroup props.

Data attributes

AttributePresent when
data-slotAlways radio-group
data-variantAlways; default or card
data-orientationAlways; vertical or horizontal
data-invalidIt's invalid
data-disabledIt's disabled
data-readonlyIt's read-only
data-requiredIt's required

RadioGroupItem

Renders React Aria's RadioField, with its label in a RadioButton. Children are the label.

Props

Prop

Type

Also accepts React Aria RadioField props, including value.

Data attributes

AttributePresent when
data-slotAlways: radio-group-item-field on the root, radio-group-item on the label, radio-group-indicator on the dot
data-selectedIt's selected
data-disabledIt's disabled
data-invalidIts group is invalid
data-requiredIts group is required
data-hoveredOn the label, while a pointer hovers it
data-pressedOn the label, while it's pressed
data-focus-visibleOn the label, while it has keyboard focus