# Collapsible

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

- Kind: ui · Category: Data display · Interactivity: native
- Install: `npx shadcn@latest add @haze/collapsible`
- File: `src/components/haze/ui/collapsible.astro`
- npm dependencies: @lucide/astro
- Registry dependencies: @haze/utils
- Docs page: https://hazeui.com/ui/collapsible

## Use 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 when
- A fixed list of questions and answers; accordion renders those from data
- Content the reader needs to see to finish the task

## Alternatives
- [accordion](https://hazeui.com/ui/accordion.md)
- [tabs](https://hazeui.com/ui/tabs.md)

## Props

| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| title | `string` |  | yes | Text of the summary row. |
| open | `boolean` | false | no | Starts expanded. |
| name | `string` |  | no | Collapsibles with the same name close each other, so only one is open. |
| class | `string` |  | no | Extra classes on the details element. |
| default slot | `slot` |  | yes | The content shown when open. |

## 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.
- Key Enter / Space: Open or close the focused summary

## Agent prompts

### 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": "https://hazeui.com/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: https://hazeui.com/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.

## Example requests that should lead here
- Add a collapsible called Advanced options under the form
- Make three collapsibles that open one at a time

## Source

```astro
---
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>
```
