Skip to content

Components / Radio Group

Radio Group

One choice from a set. A monospaced Radix radio group with a circular dot, clear labels and visible keyboard focus, designed to sit alongside square YADS controls.

Storybook runs locally or as a separately hosted build; no hosted Storybook is configured. Sources and setup links match the install revision.

Usage playground

Choose one delivery speed. Try arrow keys and Space, change orientation, or preview disabled and explicitly invalid states. Priority is unavailable in every preview.

Delivery speed

React / TSX
'use client';

import { useId, useState } from 'react';
import { RadioGroup, RadioGroupItem } from '@/components/ui/yads-radio-group';
import { Label } from '@/components/ui/yads-label';

Installation

pnpm dlx [email protected] add biehlio/yet-another-design-system/radio-group#e7b31d0e0c9d8b24d53e97ca38b3b68d345e9f40

Documentation samples use basic Tailwind utilities for layout. Install each YADS component imported by the sample.

Run in a project configured for shadcn. This installs yads-radio-group, its scoped stylesheet, @radix-ui/react-radio-group and pinned JetBrains Mono. Import RadioGroup and RadioGroupItem from @/components/ui/yads-radio-group; adjust the alias to your project. The primitive needs no Tailwind, global CSS, reset, theme provider or form library.

Samples copy complete React modules and recipe CSS even when collapsed, with client boundaries for React Server Component apps. They use basic Tailwind layout and separately installed YADS Label and Button. Install these companions for the samples (they are not Radio Group dependencies):

pnpm dlx [email protected] add biehlio/yet-another-design-system/label#e7b31d0e0c9d8b24d53e97ca38b3b68d345e9f40 biehlio/yet-another-design-system/button#e7b31d0e0c9d8b24d53e97ca38b3b68d345e9f40

Helper text and errors

Name the group with aria-labelledby and each item with an external label. Connect help and errors using aria-describedby on the group. This application-owned example starts with an error and removes it when you choose; the primitive generates no feedback.

Delivery speed (required)

Standard arrives in 3–5 working days; Express in 1–2.

Choose a delivery speed.

React / TSX
'use client';

import { useId, useState } from 'react';
import { RadioGroup, RadioGroupItem } from '@/components/ui/yads-radio-group';
import { Label } from '@/components/ui/yads-label';

Native form submission

Uncontrolled defaultValue, required and name work with Radix’s internal native radio inputs. Only the enabled selected value enters FormData. A required group with no selection blocks browser submission. This local demo sends no request.

Reset restores Standard and clears the result. Verified with Radix 1.5.1: native form reset restores the group’s initial value, including an explicitly form-associated external group. Controlled groups must accept onValueChange updates; this wrapper adds no reset logic.

Delivery speed (required)

React / TSX
'use client';

import { useId, useState } from 'react';
import { RadioGroup, RadioGroupItem } from '@/components/ui/yads-radio-group';
import { Label } from '@/components/ui/yads-label';
import { Button } from '@/components/ui/yads-button';

className customization

Increase the circular target and border using ordinary CSS. Keep the dot, theme colors, disabled treatment and focus ring. className and style pass through independently on the group and item; the copied module includes the recipe CSS.

Receipt format

React / TSX
'use client';

import { useId } from 'react';
import { RadioGroup, RadioGroupItem } from '@/components/ui/yads-radio-group';
import { Label } from '@/components/ui/yads-label';

Accessibility

  • Name both levels. Use a visible group heading and aria-labelledby on RadioGroup. Give every RadioGroupItem a unique id and an external label with matching htmlFor. useId keeps repeated examples distinct. Do not place unrelated interactive content in labels.
  • Keep one choice. Radio groups select one option, not independent booleans. The circular dot remains recognizable next to square YADS controls. Disabled choices stay visible but cannot be selected; explain their unavailability in text.
  • Preserve keyboard navigation. Tab enters on the checked item (or an enabled item when empty) and leaves the group in one step. Shift-Tab reverses entry/exit. Arrows move focus and select, skipping disabled items; Space selects the focused item. Enter on a radio does not submit the form; use its submit button.
  • Explain feedback. Mark requirements visibly and with required. Set aria-invalid only when your application shows an error, and link helper/error IDs with aria-describedby. Error text, not color alone, explains what to change. There is no readOnly radio API or built-in validation message.
  • Use native form support deliberately. Radix creates internal native inputs for name, required, disabled and form. Use a distinct name per form group so browser validation groups the inputs correctly. The ref targets a button; onValueChange is the selection callback, not an input onChange. Reset is provided by the tested upstream version, not a YADS patch. Do not cancel reset and assume browser/input state stays synchronized.

Standalone light styles require no site CSS, reset, Tailwind or theme provider. A containing .dark class activates scoped dark colors. External label/help typography belongs to the consumer; the installed YADS Label is a useful companion.

API reference

Import { RadioGroup, RadioGroupItem, type RadioGroupProps, type RadioGroupItemProps } from @/components/ui/yads-radio-group. Props are the underlying @radix-ui/react-radio-group Root and Item props with forwarded refs. No field wrapper, validation algorithm or card-choice API is added.

On narrow screens, focus the table and scroll horizontally to read all columns.

Radio Group props, types, defaults and behavior
PropTypeDefaultDescription
Root: value / onValueChangestring | null / (value: string) => voidUncontrolledControlled selection. Accept updates synchronously, including reset updates. Do not switch controlledness.
Root: defaultValuestringNo selectionInitial uncontrolled selection. Native reset restores the initial value in tested Radix 1.5.1. Do not combine with value.
Root: name / formstringNot setUse a distinct name per form group for native radio grouping, validation and submission. form associates internal inputs with a form ID, including outside the form.
Root: required / disabledbooleanfalse / falseRequired uses native constraint validation in a form. Disabled disables all items and omits them from submission.
Root: orientation"horizontal" | "vertical"Not setUnset: grid layout and both arrow axes. Vertical uses Up/Down; horizontal uses Left/Right with wrapping flex layout. Visual wrapping does not add two-dimensional keyboard navigation.
Root: dir / loop"ltr" | "rtl" / booleanInherited direction / trueDirection affects horizontal arrows. Loop wraps at the ends; false stops at the first/last enabled item.
Item: valuestringRequiredUnique value within the group. Exactly one matching item can be checked; do not duplicate values.
Item: disabledbooleanfalseSkips the item during keyboard navigation and excludes its native input from submission.
Root / Item: id, aria-*Native attributesNot setName the group via aria-labelledby or aria-label and each item with label htmlFor + id. Connect help/errors with aria-describedby. aria-invalid=true styles errors but does not validate.
Root / Item: className / stylestring / CSSPropertiesNot setMerged scoped class and forwarded inline styles. No size or variant API.
Root / Item: asChildbooleanfalseCompose onto one compatible child element via Radix. Keep Item as a focusable button; preserve radio semantics. The local decorative indicator is retained.
Root / Item: refRef<HTMLDivElement> / Ref<HTMLButtonElement>Not setUnderlying element refs. Item focus() focuses the radio button, not its internal input.

Forwarded attributes and elements

Root renders a div with role=radiogroup; Item renders a button with role=radio and a decorative local CSS indicator. Native element events, data-* and aria-* pass through. Radix manages checked state, roving tab order and internal inputs. Avoid overriding role, type or tabIndex. Place labels/help outside the item; no IDs or names are generated automatically.

Playground defaults

Reset restores Standard, vertical orientation and enabled state. Priority remains individually disabled. The state selector is a documentation control, not a custom component prop. The invalid preview demonstrates application-supplied feedback; it does not block submission by itself.