Skip to content
Haze UI

Segmented Control

Optical-sized segmented track with a sliding raised indicator for exclusive filters, view modes, or route links.

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

When to use

  • Switching between three compact view filters such as 24h, 7d, and 30d without rendering tab panels
  • Rendering top-level route links inside a raised-key navigation track with aria-current="page"
  • Aligning an exclusive mode toggle beside standard sm, md, or lg buttons

When not to use

  • Each item swaps a local content panel in the same page; use tabs for full tabpanel ARIA semantics
  • Selecting an option inside a submitted HTML form; use toggle-group or radio-group

Installation

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

pnpm dlx shadcn@latest add @haze/segmented-control
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 label applied to the nav or group landmark.
items*{ value: string; label: string; href?: string; disabled?: boolean }[]–Segments rendered as links when href is provided, otherwise exclusive toggle buttons.
valuestring–Active segment value; defaults to the first enabled item.
size"sm" | "md" | "lg""md"Height and padding matched to Haze button and tab sizes.
fullWidthbooleanfalseDistributes segments equally across the container width.
classstring–Extra classes on the outer track.

Keyboard interactions

Tab
Move focus between enabled segment links or buttons
EnterSpace
Activate the focused segment

Accessibility

  • Uses <nav> with aria-current="page" for linked items and role="group" with aria-pressed for mode buttons.
  • Emits a custom haze:segmented-change event carrying { value } when a button segment is activated.
  • Places the sliding indicator synchronously on first paint and honors prefers-reduced-motion.

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 "Segmented Control" with `npx shadcn@latest add @haze/segmented-control`. 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 SegmentedControl from "@/components/haze/ui/segmented-control.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/segmented-control.md

  • Customize with real content

    Adapt the Haze segmented-control ui for our product. Replace the demo values of these props with our real content: label, items, value, size, fullWidth, class. Keep the layout, the heading level rules and these accessibility details: Uses <nav> with aria-current="page" for linked items and role="group" with aria-pressed for mode buttons. Emits a custom haze:segmented-change event carrying { value } when a button segment is activated. Places the sliding indicator synchronously on first paint and honors prefers-reduced-motion. Do not add raw color classes; use the Haze tokens.

  • Choose the right block

    Before using segmented-control, check it fits: use it when switching between three compact view filters such as 24h, 7d, and 30d without rendering tab panels; rendering top-level route links inside a raised-key navigation track with aria-current="page"; aligning an exclusive mode toggle beside standard sm, md, or lg buttons. Avoid it when each item swaps a local content panel in the same page; use tabs for full tabpanel aria semantics; selecting an option inside a submitted html form; use toggle-group or radio-group. Alternatives: @haze/tabs, @haze/toggle-group, @haze/radio-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