# Collapsible

Shows and hides a section. Disclosure is the styled version: a 36 px trigger row with a chevron, a 13 px title and an optional muted count, and its content indented 32 px under the title. Accordion is several of them working together. The content grows to its height as it opens.

- Beta: ready to use; its API can still change in a minor release.
- Category: Layout & surfaces

```tsx
import { Disclosure, Accordion, AccordionItem, Collapsible, CollapsibleTrigger, CollapsibleContent } from "@leap-crm/design-system";
```

## Best practices

- Do: Use `Disclosure` for one section the reader opens on demand, like a matter's billing details, so it sits closed on a 36 px row until needed.
- Do: Use `Accordion` for a stack of sections where one open at a time keeps the panel short. Set `multiple` when a lawyer needs to compare two.
- Do: Put a short muted note in `meta`, like "4 fields", so the reader knows what is inside before opening it.
- Do: Use bare `Collapsible` with `CollapsibleTrigger` and `render` only when the trigger is your own control, like a Show more link under a list.
- Don't: Hide a required field inside a closed section. Its error would be out of sight when the form fails to save.

## Keyboard

| Keys | What they do |
| --- | --- |
| Enter, Space | Toggle the panel and keep focus on the trigger. |
| Tab | Moves from an open trigger into its panel, and skips a closed panel. |

## Related

- [Section Header](./section-header.md)
- [Tabs](./tabs.md)
- [Pilot](./pilot.md)

## Examples

What the examples import:

```tsx
import { Accordion, AccordionItem, Button, Collapsible, CollapsibleContent, CollapsibleTrigger, Disclosure } from "@leap-crm/design-system";
```

### Disclosure

Closed, open, and without a count. Hover shades the row; Tab to see focus.

```tsx
<div className="flex w-96 flex-col gap-2">
  <Disclosure title="Matter details" meta="4 fields">
    Matter type, responsible staff, practice area and billing.
  </Disclosure>
  <Disclosure title="Matter details" meta="4 fields" defaultOpen>
    Matter type, responsible staff, practice area and billing. The
    content sits 32 px in, under the title.
  </Disclosure>
  <Disclosure title="Notes">No notes yet.</Disclosure>
</div>
```

### Disabled

```tsx
<div className="w-96">
  <Disclosure title="Billing" meta="Locked" disabled>
    Billing is set in LEAP.
  </Disclosure>
</div>
```

### Your own trigger

Compose Collapsible, CollapsibleTrigger and CollapsibleContent when the trigger isn't a row, like a Show more button. Pass the control to render.

```tsx
<Collapsible className="flex w-96 flex-col gap-2">
  <p className="text-body">
    Jane Citizen is buying a house in Paddington with her partner.
  </p>
  <CollapsibleContent>
    <p className="text-body text-neutral-text-secondary">
      Settlement is booked for 14 December. The contract was exchanged
      on 2 November, and the deposit is held in trust.
    </p>
  </CollapsibleContent>
  <CollapsibleTrigger
    render={
      <Button intent="ghost" size="sm" className="self-start">
        Show more
      </Button>
    }
  />
</Collapsible>
```

### Several together: Accordion

Accordion stacks disclosures on dividers and coordinates them: opening one closes the other, and the arrow keys move between headers. Each header is a heading, so screen reader users can jump between sections.

```tsx
<Accordion defaultValue={["details"]} className="w-96">
  <AccordionItem value="details" title="Matter details" meta="3 fields">
    Conveyancing · Purchase · Ada Hartley responsible
  </AccordionItem>
  <AccordionItem value="parties" title="Parties" meta="4 parties">
    Jane Citizen, John Citizen, Paddington Realty, Westpac.
  </AccordionItem>
  <AccordionItem value="billing" title="Billing" meta="2 rates">
    Fixed fee $2,200, disbursements at cost.
  </AccordionItem>
</Accordion>
```

### Accordion, several open

multiple lets several items stay open together.

```tsx
<Accordion
  multiple
  defaultValue={["details", "billing"]}
  className="w-96"
>
  <AccordionItem value="details" title="Matter details" meta="3 fields">
    Conveyancing · Purchase · Ada Hartley responsible
  </AccordionItem>
  <AccordionItem value="parties" title="Parties" meta="4 parties">
    Jane Citizen, John Citizen, Paddington Realty, Westpac.
  </AccordionItem>
  <AccordionItem value="billing" title="Billing" meta="2 rates">
    Fixed fee $2,200, disbursements at cost.
  </AccordionItem>
</Accordion>
```

## Props

Collapsible and Disclosure take ui-sdk's Collapsible options: open, defaultOpen, onOpenChange, disabled and controller. CollapsibleTrigger takes render. Accordion takes ui-sdk's Accordion options: value, defaultValue, onValueChange, multiple, collapsible, disabled and keepMounted; AccordionItem takes value and disabled.

### Disclosure

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `title` (required) | `ReactNode` |  | The 13 px title on the 36 px trigger row. |
| `meta` | `ReactNode` |  | A short muted note on the right of the trigger, like "4 fields". |
| `children` | `ReactNode` |  | What opens, 32 px in, under the title. |
| `className` | `string` |  | Classes added to the root element, merged with its own. Tokens only. |

### Accordion

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` | `ReactNode` |  | What it shows inside. |
| `className` | `string` |  | Classes added to the root element, merged with its own. Tokens only. |

### AccordionItem

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `title` (required) | `ReactNode` |  | The 13 px title on the 36 px header row. |
| `meta` | `ReactNode` |  | A short muted note on the right of the header, like "3 fields". |
| `children` | `ReactNode` |  | What opens, 32 px in, under the title. |
| `className` | `string` |  | Classes added to the root element, merged with its own. Tokens only. |

### Collapsible

No props of its own.

### CollapsibleTrigger

No props of its own.

### CollapsibleContent

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` | `ReactNode` |  | What it shows inside. |
| `className` | `string` |  | Classes added to the root element, merged with its own. Tokens only. |
