Skip to content
Haze UI

Radio group

Fieldset with a legend and a list of radios, each with a label and optional description; vertical or horizontal.

pnpm dlx shadcn@latest add @haze/radio-group
Open preview in a new tab
Liveno JavaScript

When to use

  • Choosing exactly one of two to five options that are worth showing at once
  • Options that need a short explanation under each label
  • Settings such as visibility, delivery speed or export format

When not to use

  • More than about six options; use select
  • A compact segmented switch between views; use toggle-group
  • Options presented as large cards; use choice-card

Installation

Add the Haze registry to components.json once, then install Radio group with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.

pnpm dlx shadcn@latest add @haze/radio-group
First time? Registry and theme setup

1. Add to components.json:

{
  "registries": {
    "@haze": "http://localhost:4329/r/{name}.json"
  }
}

2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";

API reference

PropTypeDefaultDescription
name*string–Shared radio name and id prefix; each radio gets the id <name>-<value>.
legend*string–Visible question or group title.
options*{ value: string; label: string; description?: string; disabled?: boolean }[]–The choices; values must be unique within the group.
valuestring–Value of the radio that is checked on load.
orientation"vertical" | "horizontal""vertical"Stacks the options or lays them in a wrapping row.
requiredboolean–One option must be picked before the form submits.
disabledboolean–Disables every option.
classstring–Extra classes on the fieldset.
...restattributes–Any other fieldset attribute, for example form or aria-describedby.

Keyboard interactions

Arrow UpArrow Down (or LeftRight)
Moves to the next or previous radio and selects it
Tab
Enters or leaves the group at the checked radio
Space
Selects the focused radio if none is checked yet

Accessibility

  • The fieldset and legend give screen readers the group's name when focus enters the first radio.
  • Radios share one name, so the browser keeps a single tab stop for the group and moves selection with the arrow keys.
  • The dot scales in over 200 ms. The circle border is foreground at 40%, which meets 3:1 against the surface.
  • Descriptions are tied to their own radio through aria-describedby, not to the group.

Notes for AI

Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.

  • Install and use

    Install the Haze UI component "Radio group" with `npx shadcn@latest add @haze/radio-group`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "http://localhost:4329/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import RadioGroup from "@/components/haze/ui/radio-group.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: http://localhost:4329/ui/radio-group.md

  • Customize with real content

    Adapt the Haze radio-group ui for our product. Replace the demo values of these props with our real content: name, legend, options, value, orientation, required, disabled, class, ...rest. Keep the layout, the heading level rules and these accessibility details: The fieldset and legend give screen readers the group's name when focus enters the first radio. Radios share one name, so the browser keeps a single tab stop for the group and moves selection with the arrow keys. The dot scales in over 200 ms. The circle border is foreground at 40%, which meets 3:1 against the surface. Descriptions are tied to their own radio through aria-describedby, not to the group. Do not add raw color classes; use the Haze tokens.

  • Choose the right block

    Before using radio-group, check it fits: use it when choosing exactly one of two to five options that are worth showing at once; options that need a short explanation under each label; settings such as visibility, delivery speed or export format. Avoid it when more than about six options; use select; a compact segmented switch between views; use toggle-group; options presented as large cards; use choice-card. Alternatives: @haze/select, @haze/toggle-group, @haze/choice-card, @haze/checkbox.

Dependencies

  • @haze/utils
  • @haze/theme (one-time setup)

Source · Original Haze UI work.

Catalog

↑↓ moveEnter openEsc close

Keyboard shortcuts

CtrlK
Command palette
/
Focus search
←↑→↓
Move between cards
jk
Next / previous card
ci
Copy code / install command (detail page)
[]
Previous / next entry
?
This help
Esc
Close dialog