Skip to content
Haze UI

Toggle group

A native radio segmented control with one selected key that glides between options when enhanced.

pnpm dlx shadcn@latest add @haze/toggle-group
Open preview in a new tab
Livesmall script

When to use

  • Switching a view or a filter between two to four short options, such as list, grid or board
  • Choosing a time range or a billing period next to a chart or table

When not to use

  • Navigating between panels of content; use tabs
  • Options with descriptions or more than five items; use radio-group or select
  • Turning a single setting on or off; use switch

Installation

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

pnpm dlx shadcn@latest add @haze/toggle-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; the form submits the selected value under it.
legend*string–Accessible name of the group, for example "Time range".
hideLegendbooleantrueHides the legend visually with sr-only; set false to show it above the control.
options*{ value: string; label: string }[]–The segments, in display order.
valuestring–Value of the segment that is selected on load.
size"sm" | "md""md"Segment height and text size.
classstring–Extra classes on the fieldset.

Keyboard interactions

Arrow LeftArrow Right
Moves to the neighbouring segment and selects it
Tab
Enters or leaves the group at the selected segment

Accessibility

  • Each segment is a real radio inside its label, so the group announces as a radio group with the legend as its name.
  • The selected segment is drawn as a raised key with a border and a shadow, not only a color change, and the radio state is exposed to assistive technology. Under forced colors the selected segment keeps a highlighted border.
  • A segment gets a short press animation, which the theme switches off under prefers-reduced-motion.
  • The shared key moves after a real selection change, follows native form resets, and remeasures without motion after layout changes.
  • The focus outline is drawn inside the segment because the container clips overflow.

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 "Toggle group" with `npx shadcn@latest add @haze/toggle-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 ToggleGroup from "@/components/haze/ui/toggle-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/toggle-group.md

  • Customize with real content

    Adapt the Haze toggle-group ui for our product. Replace the demo values of these props with our real content: name, legend, hideLegend, options, value, size, class. Keep the layout, the heading level rules and these accessibility details: Each segment is a real radio inside its label, so the group announces as a radio group with the legend as its name. The selected segment is drawn as a raised key with a border and a shadow, not only a color change, and the radio state is exposed to assistive technology. Under forced colors the selected segment keeps a highlighted border. A segment gets a short press animation, which the theme switches off under prefers-reduced-motion. The shared key moves after a real selection change, follows native form resets, and remeasures without motion after layout changes. The focus outline is drawn inside the segment because the container clips overflow. Do not add raw color classes; use the Haze tokens.

  • Choose the right block

    Before using toggle-group, check it fits: use it when switching a view or a filter between two to four short options, such as list, grid or board; choosing a time range or a billing period next to a chart or table. Avoid it when navigating between panels of content; use tabs; options with descriptions or more than five items; use radio-group or select; turning a single setting on or off; use switch. Alternatives: @haze/tabs, @haze/radio-group, @haze/select, @haze/button-group.

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