Skip to content
Haze UI

Button group

Related actions share joined borders, or sit in a sunken track where a raised key slides to the pressed button.

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

When to use

  • Related actions that read as one control, such as Day, Week and Month
  • A split of a primary action and a secondary one that belong together
  • A small cluster of outline buttons that should share borders

When not to use

  • Choosing one option from a set that stays selected; toggle-group tracks pressed state
  • Unrelated actions, which need their own spacing and visual weight
  • More than about five buttons, which wrap badly on narrow screens

Installation

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

pnpm dlx shadcn@latest add @haze/button-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
label*string–Accessible name of the group, set as aria-label on the role="group" wrapper.
orientation"horizontal" | "vertical""horizontal"Row or column. The outer corners stay round, inner corners go square and borders overlap by 1 px.
variant"joined" | "segmented""joined"Joined shares borders between outline buttons. Segmented is a sunken track of ghost buttons; a raised key slides to the child with aria-pressed="true", which your own script toggles.
classstring–Extra classes on the wrapper.
default slot*slot–Button components; the outline variant looks best because it has a border to share.

Keyboard interactions

Tab
Each button in the group is its own tab stop; Enter or Space activates the focused one

Accessibility

  • role="group" with a required label tells a screen reader that the buttons belong together, for example "Time range, group".
  • A focused or hovered button is raised with z-10 so its ring and border are not covered by the neighbor that overlaps it by 1 px.
  • Buttons in the group do not shrink when pressed, so the joined edges stay aligned.
  • The group sets no pressed state itself; for a single choice that manages its own state, use toggle-group or segmented-control.
  • In the segmented variant the sliding key is decorative; the state is the aria-pressed attribute on each button, which your script must keep in sync, and the key follows it.
  • Every action keeps its native activation and tab stop; the key never takes pointer events.

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

  • Customize with real content

    Adapt the Haze button-group ui for our product. Replace the demo values of these props with our real content: label, orientation, variant, class, default slot. Keep the layout, the heading level rules and these accessibility details: role="group" with a required label tells a screen reader that the buttons belong together, for example "Time range, group". A focused or hovered button is raised with z-10 so its ring and border are not covered by the neighbor that overlaps it by 1 px. Buttons in the group do not shrink when pressed, so the joined edges stay aligned. The group sets no pressed state itself; for a single choice that manages its own state, use toggle-group or segmented-control. In the segmented variant the sliding key is decorative; the state is the aria-pressed attribute on each button, which your script must keep in sync, and the key follows it. Every action keeps its native activation and tab stop; the key never takes pointer events. Do not add raw color classes; use the Haze tokens.

  • Choose the right block

    Before using button-group, check it fits: use it when related actions that read as one control, such as day, week and month; a split of a primary action and a secondary one that belong together; a small cluster of outline buttons that should share borders. Avoid it when choosing one option from a set that stays selected; toggle-group tracks pressed state; unrelated actions, which need their own spacing and visual weight; more than about five buttons, which wrap badly on narrow screens. Alternatives: @haze/button, @haze/toggle-group, @haze/tabs.

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