nook
Browse the docs

Components

Radio Group

Built on Base UI

Pick exactly one option from a small set, with arrow key navigation.

See the prompt

Installation

npx nook-ui@latest add radio-group

Prompt

Paste this into your AI coding assistant. It adds this exact component, the same way the CLI does, and tells the assistant how to use it.

Short. For assistants that can run commands in your project.

Plain text
Add the Nook "Radio Group" component to this project, exactly as Nook ships it.

Pick exactly one option from a small set, with arrow key navigation.

Steps
1. Check for `nook.json` in the project root. If it is missing, run `npx nook-ui@latest init` first (React or Next.js with Tailwind CSS v4). It adds the Nook tokens, the theme and `cn()`.
2. Run `npx nook-ui@latest add radio-group`. It writes `components/ui/radio-group.tsx` together with everything the component needs. Do not write the component from memory.
3. If you cannot run commands, fetch http://localhost:3000/r/radio-group.json, write every entry of `files` to the path it names, install the packages in `dependencies`, and repeat for each name in `registryDependencies`.
4. Use it where I ask. Start from this example:

```tsx
import { Label } from "@/components/ui/label";
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group";

export default function RadioGroupDefault() {
  return (
    <RadioGroup defaultValue="comfortable" aria-label="Density">
      <Label>
        <RadioGroupItem value="compact" /> Compact
      </Label>
      <Label>
        <RadioGroupItem value="comfortable" /> Comfortable
      </Label>
      <Label>
        <RadioGroupItem value="spacious" /> Spacious
      </Label>
    </RadioGroup>
  );
}
```

API
- `RadioGroup`: Wraps the items and owns the value.
  - `value` (`string`): Controlled value.
  - `defaultValue` (`string`): Initial value when uncontrolled.
  - `onValueChange` (`(value: string) => void`): Called when the selection changes.
  - `disabled` (`boolean`, default false): Disables every item.
  - `name` (`string`): Name submitted with a form.
- `RadioGroupItem`: One option.
  - `value` (`string`): The value this item represents.
  - `disabled` (`boolean`, default false): Disables this item.

Rules
- Colors, radii, shadows and motion come from Nook tokens and classes such as `bg-primary`, `text-muted-foreground`, `border-border`, `rounded-lg` and `h-control`. Never hard-code them.
- Do not restyle or simplify the file. Change how it looks through `className`, its props and the theme.
- It must keep working with the keyboard, in light and dark mode, and in the sharp, soft and bold styles.
- Accessibility: Arrow keys move and select. Give the group an accessible name with `aria-label` or `aria-labelledby`.

Done when the component renders like the example in light and dark mode and the project type-checks.

Usage

import { Label } from "@/components/ui/label";
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group";

export default function RadioGroupDefault() {
  return (
    <RadioGroup defaultValue="comfortable" aria-label="Density">
      <Label>
        <RadioGroupItem value="compact" /> Compact
      </Label>
      <Label>
        <RadioGroupItem value="comfortable" /> Comfortable
      </Label>
      <Label>
        <RadioGroupItem value="spacious" /> Spacious
      </Label>
    </RadioGroup>
  );
}

Examples

With descriptions

A short line under each choice says what it does.

Anyone with the link can view.

Only people in Acme Studio.

Hidden from search and sharing.

Inline

Short choices can sit in a row.

Disabled choices

Disable one choice or the whole group.

Required choice

Mark the group invalid and say what is missing.

Pick a size to continue.

Props

RadioGroup

Wraps the items and owns the value.

PropTypeDefaultDescription
valuestring–Controlled value.
defaultValuestring–Initial value when uncontrolled.
onValueChange(value: string) => void–Called when the selection changes.
disabledbooleanfalseDisables every item.
namestring–Name submitted with a form.

RadioGroupItem

One option.

PropTypeDefaultDescription
valuestring–The value this item represents.
disabledbooleanfalseDisables this item.

Accessibility

Arrow keys move and select. Give the group an accessible name with `aria-label` or `aria-labelledby`.

Checked against WCAG 2.1 AA with automated axe tests and keyboard tests on every release.