Skip to content
Haze UI

Collapsible

One native details element in a bordered panel, with a chevron that turns when open and a panel that animates its height.

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

When to use

  • Hiding secondary content such as advanced options behind a single heading
  • Several sections that should behave as an accordion: give them the same name
  • Content that must work without any script

When not to use

  • A fixed list of questions and answers; accordion renders those from data
  • Content the reader needs to see to finish the task

Installation

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

pnpm dlx shadcn@latest add @haze/collapsible
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
title*string–Text of the summary row.
openbooleanfalseStarts expanded.
namestring–Collapsibles with the same name close each other, so only one is open.
classstring–Extra classes on the details element.
default slot*slot–The content shown when open.

Keyboard interactions

EnterSpace
Open or close the focused summary

Accessibility

  • The browser exposes the summary as a disclosure button with expanded state, so no ARIA is added.
  • The panel animates its height where the browser supports interpolate-size; elsewhere the content rises in. Both are switched off under prefers-reduced-motion.
  • The native triangle is hidden and replaced by a chevron icon that is aria-hidden; the title text names the control.
  • Closed content is removed from the accessibility tree and from the tab order by the browser.

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 "Collapsible" with `npx shadcn@latest add @haze/collapsible`. 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 Collapsible from "@/components/haze/ui/collapsible.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/collapsible.md

  • Customize with real content

    Adapt the Haze collapsible ui for our product. Replace the demo values of these props with our real content: title, open, name, class, default slot. Keep the layout, the heading level rules and these accessibility details: The browser exposes the summary as a disclosure button with expanded state, so no ARIA is added. The panel animates its height where the browser supports interpolate-size; elsewhere the content rises in. Both are switched off under prefers-reduced-motion. The native triangle is hidden and replaced by a chevron icon that is aria-hidden; the title text names the control. Closed content is removed from the accessibility tree and from the tab order by the browser. Do not add raw color classes; use the Haze tokens.

  • Choose the right block

    Before using collapsible, check it fits: use it when hiding secondary content such as advanced options behind a single heading; several sections that should behave as an accordion: give them the same name; content that must work without any script. Avoid it when a fixed list of questions and answers; accordion renders those from data; content the reader needs to see to finish the task. Alternatives: @haze/accordion, @haze/tabs.

Dependencies

  • npm: @lucide/astro
  • @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