# Radio Group

Choose one value from a mutually exclusive set.

Choose one value from a mutually exclusive set.

<p className="zenos-base-ui-source">
  Backed by <a href="https://base-ui.com/react/components/radio-group">Base UI Radio Group</a> for
  upstream behavior and configuration. Zenos owns the public API, styling, and composition shown on
  this page.
</p>

```tsx
import { Label, RadioGroup, Stack } from "@zentara-co/zenos-ui";

function RadioGroupExample() {
  return (
    <RadioGroup.Root defaultValue="daily" aria-label="Scan cadence" className="gap-3">
      <Stack direction="row" gap="2" align="center">
        <RadioGroup.Item id="scan-daily" value="daily" />
        <Label htmlFor="scan-daily">Daily</Label>
      </Stack>
      <Stack direction="row" gap="2" align="center">
        <RadioGroup.Item id="scan-weekly" value="weekly" />
        <Label htmlFor="scan-weekly">Weekly</Label>
      </Stack>
    </RadioGroup.Root>
  );
}
```

## Import

```tsx
import { Label, RadioGroup } from "@zentara-co/zenos-ui";
```

State follows `value`, `defaultValue`, and `onValueChange`. Arrow keys move selection within the group, while disabled items remain unavailable.

## Sizes

Use `size="sm"`, `size="md"`, or `size="lg"` for 32px, 40px, or 48px hit targets. The visible radio controls are 16px, 20px, and 24px, matching the Checkbox size scale.

```tsx
import { Label, RadioGroup, Stack } from "@zentara-co/zenos-ui";

function RadioGroupSizesExample() {
  return (
    <Stack direction="row" gap="6" align="center" wrap="wrap" className="justify-center">
      {(["sm", "md", "lg"] as const).map((size) => (
        <Stack key={size} direction="row" gap="1" align="center">
          <RadioGroup.Root defaultValue={size} aria-label={`${size} radio size`}>
            <RadioGroup.Item id={`radio-${size}`} value={size} size={size} />
          </RadioGroup.Root>
          <Label htmlFor={`radio-${size}`} className="capitalize">
            {size === "sm" ? "Small" : size === "md" ? "Medium" : "Large"}
          </Label>
        </Stack>
      ))}
    </Stack>
  );
}
```

## Custom styling

Use `className` on the group, labels, and items to create a custom treatment while Base UI continues to own selection and keyboard behavior. `RadioGroup.Item` exposes `data-checked` for state styling, and stable slots such as `radio-box` let parent-scoped selectors customize the visible control without replacing it.

```tsx
import { Label, RadioGroup, Stack, Text } from "@zentara-co/zenos-ui";

function RadioGroupCustomStylingExample() {
  const options = [
    ["focused", "Focused", "Only the updates that need your attention."],
    ["balanced", "Balanced", "Important updates with a concise daily summary."],
    ["complete", "Complete", "Every workspace event as it happens."],
  ] as const;

  return (
    <RadioGroup.Root
      defaultValue="balanced"
      aria-label="Notification detail"
      className="w-full max-w-md gap-2 rounded-xl border border-border-accent-purple-default bg-background-accent-purple-subtlest-default p-2"
    >
      {options.map(([value, title, description]) => (
        <Label
          key={value}
          className="flex cursor-pointer items-center gap-3 rounded-lg border border-transparent bg-background-neutral-card p-3 transition-colors hover:bg-background-accent-purple-subtlest-hover has-[[data-checked]]:border-border-accent-purple-default has-[[data-checked]]:bg-background-accent-purple-subtlest-pressed"
        >
          <RadioGroup.Item
            value={value}
            className="[&_[data-slot=radio-box]]:border-border-accent-purple-default [&_[data-slot=radio-box]]:bg-background-neutral-card [&[data-checked]_[data-slot=radio-box]]:border-background-accent-purple-bolder-default [&[data-checked]_[data-slot=radio-box]]:bg-background-accent-purple-bolder-default"
          />
          <Stack gap="0">
            <Text weight="medium" className="text-text-accent-purple-bolder">
              {title}
            </Text>
            <Text size="s" color="subtle">
              {description}
            </Text>
          </Stack>
        </Label>
      ))}
    </RadioGroup.Root>
  );
}
```

## Controlled value

Use controlled state when another part of the interface needs the selected value immediately.

```tsx
import { Label, RadioGroup, Stack, Text } from "@zentara-co/zenos-ui";
import { useState } from "react";

function RadioGroupControlledExample() {
  const [cadence, setCadence] = useState("weekly");
  return (
    <Stack gap="3" className="w-full max-w-sm">
      <RadioGroup.Root
        value={cadence}
        onValueChange={setCadence}
        aria-label="Report cadence"
        className="gap-3"
      >
        {[
          ["daily", "Daily"],
          ["weekly", "Weekly"],
          ["monthly", "Monthly"],
        ].map(([value, label]) => (
          <Stack key={value} direction="row" gap="2" align="center">
            <RadioGroup.Item id={`cadence-${value}`} value={value} />
            <Label htmlFor={`cadence-${value}`}>{label}</Label>
          </Stack>
        ))}
      </RadioGroup.Root>
      <Text size="s" color="subtle">
        Selected: {cadence}
      </Text>
    </Stack>
  );
}
```

## Arrangement

RadioGroup uses a vertical grid by default. Use `className` for a horizontal arrangement when the labels remain readable in the available width. Base UI continues to manage radio-group keyboard movement.

```tsx
import { Label, RadioGroup, Stack, Text } from "@zentara-co/zenos-ui";

function RadioGroupOrientationExample() {
  return (
    <Stack gap="6" className="w-full">
      <Stack gap="2">
        <Text size="s" weight="medium">
          Horizontal
        </Text>
        <RadioGroup.Root defaultValue="week" aria-label="Date range" className="flex gap-5">
          {[
            ["day", "Day"],
            ["week", "Week"],
            ["month", "Month"],
          ].map(([value, label]) => (
            <Label key={value} className="cursor-pointer">
              <RadioGroup.Item value={value} /> {label}
            </Label>
          ))}
        </RadioGroup.Root>
      </Stack>
      <Stack gap="2">
        <Text size="s" weight="medium">
          Vertical
        </Text>
        <RadioGroup.Root defaultValue="email" aria-label="Delivery method">
          <Label className="cursor-pointer">
            <RadioGroup.Item value="email" /> Email
          </Label>
          <Label className="cursor-pointer">
            <RadioGroup.Item value="webhook" /> Webhook
          </Label>
        </RadioGroup.Root>
      </Stack>
    </Stack>
  );
}
```

## States and custom indicator

Disable the complete group from Root or individual unavailable choices from Item. Pass custom content to Item when the default indicator does not fit the interface.

```tsx
import { Label, RadioGroup, Stack } from "@zentara-co/zenos-ui";

function RadioGroupStatesExample() {
  return (
    <Stack gap="4" className="w-full max-w-sm">
      <Stack direction="row" gap="1" align="center">
        <RadioGroup.Root defaultValue="checked" aria-label="Selected">
          <RadioGroup.Item id="radio-checked" value="checked" />
        </RadioGroup.Root>
        <Label htmlFor="radio-checked">Selected</Label>
      </Stack>
      <Stack direction="row" gap="1" align="center">
        <RadioGroup.Root aria-label="Invalid unchecked">
          <RadioGroup.Item id="radio-invalid" value="one" aria-invalid="true" />
        </RadioGroup.Root>
        <Label htmlFor="radio-invalid">Invalid</Label>
      </Stack>
      <Stack direction="row" gap="1" align="center">
        <RadioGroup.Root defaultValue="bad" aria-label="Invalid selected">
          <RadioGroup.Item id="radio-invalid-checked" value="bad" aria-invalid="true" />
        </RadioGroup.Root>
        <Label htmlFor="radio-invalid-checked">Invalid selected</Label>
      </Stack>
      <Stack direction="row" gap="1" align="center">
        <RadioGroup.Root aria-label="Disabled">
          <RadioGroup.Item id="radio-disabled" value="off" disabled />
        </RadioGroup.Root>
        <Label htmlFor="radio-disabled">Disabled</Label>
      </Stack>
      <Stack direction="row" gap="1" align="center">
        <RadioGroup.Root defaultValue="on" aria-label="Disabled selected">
          <RadioGroup.Item id="radio-disabled-checked" value="on" disabled />
        </RadioGroup.Root>
        <Label htmlFor="radio-disabled-checked">Disabled selected</Label>
      </Stack>
    </Stack>
  );
}
```

## Anatomy

```text
RadioGroup.Root
RadioGroup.Item
RadioGroup.Indicator
```

## API

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| value | string | — | Controlled selected value. |
| defaultValue | string | — | Initial uncontrolled value. |
| onValueChange | (value: string, eventDetails) => void | — | Runs when selection changes. |
| name | string | — | Form field name shared by the group items. |
| disabled / required | boolean | false | Group form semantics. |
| Item.disabled | boolean | false | Prevents selection of an individual option. |
| Item.size | sm \| md \| lg | md | 32px, 40px, or 48px hit target with a proportionally sized circle. |
| Item.children | ReactNode | — | Replaces the default RadioGroup.Indicator. |

Unless narrowed above, each DOM-rendering part also accepts its underlying native or Base UI props, including className, style, aria-*, and data-*.

## Accessibility

Give every group an accessible name with a visible group label, `aria-label`, or `aria-labelledby`. Associate each option with Label by wrapping it or matching `htmlFor` and `id`. Arrow keys move focus and selection within the group, while Tab enters and leaves it. Disabled items are skipped. Required and invalid state must be paired with visible guidance when users need help correcting a selection.

Source: https://zenos-ui.pages.dev/components/radio-group/