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---
import { ChevronDown } from "@lucide/astro";
import { cn } from "../../../lib/haze/utils";
interface Props {
title: string;
open?: boolean;
/** Collapsibles that share a name open one at a time. */
name?: string;
class?: string;
}
const { title, open = false, name, class: className } = Astro.props;
// Where the browser can animate to height:auto, the panel slides open and shut. Elsewhere its content rises in.
const slide =
"supports-[interpolate-size:allow-keywords]:[interpolate-size:allow-keywords] supports-[interpolate-size:allow-keywords]:details-content:h-0 supports-[interpolate-size:allow-keywords]:details-content:overflow-clip supports-[interpolate-size:allow-keywords]:details-content:transition-[height,content-visibility] supports-[interpolate-size:allow-keywords]:details-content:transition-discrete supports-[interpolate-size:allow-keywords]:details-content:duration-300 supports-[interpolate-size:allow-keywords]:details-content:ease-snappy supports-[interpolate-size:allow-keywords]:open:details-content:h-auto";
---
<details name={name} open={open} class={cn("overflow-hidden rounded-xl border border-border bg-card", slide, className)}>
<summary
class="flex min-h-11 cursor-pointer list-none items-center justify-between gap-3 px-4 py-3 text-[0.8125rem]/5 font-medium text-foreground transition-colors duration-150 ease-snappy [details:not([open])>&]:hover:bg-accent focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring [&::-webkit-details-marker]:hidden"
>
<span>{title}</span>
<ChevronDown
class="size-4 shrink-0 text-muted-foreground transition-[rotate,color] duration-200 ease-snappy [[open]>summary_&]:rotate-180 [[open]>summary_&]:text-foreground"
aria-hidden="true"
/>
</summary>
<div class="px-4 pb-4 text-[0.8125rem]/6 text-muted-foreground not-supports-[interpolate-size:allow-keywords]:animate-rise"><slot /></div>
</details>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/collapsiblenpx shadcn@latest add @haze/collapsibleyarn dlx shadcn@latest add @haze/collapsiblebunx --bun shadcn@latest add @haze/collapsibleFirst 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
| Prop | Type | Default | Description |
|---|---|---|---|
| title* | string | – | Text of the summary row. |
| open | boolean | false | Starts expanded. |
| name | string | – | Collapsibles with the same name close each other, so only one is open. |
| class | string | – | 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.