Radio Group

One choice out of several. Built on native radio inputs, so arrow-key roving, form submission and the single-selection invariant come from the platform.

src/components/ui/radio-group.tsx

Install

npx astralyx-ui add radio-group

Usage

import { Radio, RadioGroup } from '@/components/ui/radio-group'

<RadioGroup defaultValue="week" onValueChange={setValue}>
  <Radio value="day" label="Every day" />
  <Radio value="week" label="Every week" />
  <Radio value="never" label="Never" />
</RadioGroup>

Composer

Change the props and the source below follows.

Props
tsx
<RadioGroup
  defaultValue="week"
>
  <Radio value="day" label="Every day" />
  <Radio value="week" label="Every week" />
  <Radio value="never" label="Never" />
</RadioGroup>

Examples

Sizes

Horizontal

With descriptions

Disabled group

API

Generated from the source, so it cannot fall behind the code. One table per exported component, then hooks, functions and types.

RadioGroup

Extends ComponentProps<'div'>.

PropTypeDefaultDescription
defaultValuestring | number | readonly string[]—Controlled and uncontrolled selection, on RadioGroup.
childrenReactNoderequired—
namestring—Shared input name. Generated with useId when omitted, so two groups on a page never collide.
valuestring—Controlled and uncontrolled selection, on RadioGroup.
onValueChange(value: string) => void—Fires with the chosen value.
disabledbooleanfalseOn RadioGroup, disables every item at once.
orientation'vertical' | 'horizontal''vertical'Layout direction, also reported as aria-orientation.
responsiveResponsive'sm'Breakpoint a horizontal group becomes a row at. Below it the options stack, keeping each label and its control on one line rather than wrapping between them.

Radio

Extends Omit<ComponentProps<'input'>, 'size' | 'type' | 'value'>.

PropTypeDefaultDescription
errorboolean——
size'sm' | 'default' | 'lg''default'—
valuestringrequiredRequired. Identifies the option within the group.
labelReactNode—Text beside the dot; the whole row is clickable.
descriptionReactNode—Text beside the dot; the whole row is clickable.
containerClassNamestring——