# Collapsible

A single disclosure region controlled by one trigger.

Reveal one optional region without navigating away or managing a collection of sections.

<p className="zenos-base-ui-source">
  Backed by <a href="https://base-ui.com/react/components/collapsible">Base UI Collapsible</a> for
  upstream behavior and configuration. Zenos follows the same composition model as{" "}
  <a href="https://ui.shadcn.com/docs/components/base/collapsible">shadcn/ui Collapsible</a>: an
  unstyled root, a trigger, and animated content—while keeping the compound{" "}
  <code>Collapsible.Root</code> API.
</p>

```tsx
import { Collapsible, Stack, Text } from "@zentara-co/zenos-ui";

function CollapsiblePreviewExample() {
  return (
    <Stack
      direction="row"
      gap="6"
      wrap="wrap"
      align="start"
      className="w-full max-w-4xl justify-center"
    >
      <Stack gap="2" className="min-w-72 flex-1">
        <Text size="s" className="font-medium text-text-subtle">
          default
        </Text>
        <Collapsible.Root className="w-full">
          <Collapsible.Trigger>Toggle details</Collapsible.Trigger>
          <Collapsible.Content>
            Composable trigger and content without a built-in shell.
          </Collapsible.Content>
        </Collapsible.Root>
      </Stack>
      <Stack gap="2" className="min-w-72 flex-1">
        <Text size="s" className="font-medium text-text-subtle">
          panel
        </Text>
        <Collapsible.Root variant="panel" defaultOpen className="w-full">
          <Collapsible.Trigger>Advanced settings</Collapsible.Trigger>
          <Collapsible.Content>
            Contained disclosure surface with divider and padding.
          </Collapsible.Content>
        </Collapsible.Root>
      </Stack>
    </Stack>
  );
}
```

## Composition

Build disclosures from three parts. The root owns open state; it does not impose a card shell unless you opt in.

```tsx
<Collapsible.Root>
  <Collapsible.Trigger>Toggle details</Collapsible.Trigger>
  <Collapsible.Content>Hidden content</Collapsible.Content>
</Collapsible.Root>
```

```text
Collapsible.Root
├── Collapsible.Trigger
└── Collapsible.Content
```

## Import

```tsx
import { Collapsible } from "@zentara-co/zenos-ui";
```

## Variants

`variant="default"` (implicit) keeps `Root` unstyled so you can wrap [Card](/components/card/), layout, or custom surfaces—similar to shadcn’s basic and order-detail examples. `variant="panel"` applies the contained disclosure shell (border, neutral card fill, full-width trigger row, content divider).

The preview above compares both.

## Basic

A minimal FAQ-style disclosure: inline trigger, chevron, and supporting text below.

```tsx
import { Collapsible } from "@zentara-co/zenos-ui";

function CollapsibleExample() {
  return (
    <Collapsible.Root className="w-full max-w-xl">
      <Collapsible.Trigger>Can I use this in my project?</Collapsible.Trigger>
      <Collapsible.Content>
        Yes. Free to use for personal and commercial projects. No attribution required.
      </Collapsible.Content>
    </Collapsible.Root>
  );
}
```

## Order details in a card

Compose a default collapsible inside `Card` when the trigger should sit in a product surface rather than a standalone panel.

```tsx
import { Card, Collapsible, Stack, Text } from "@zentara-co/zenos-ui";

function CollapsibleOrderExample() {
  return (
    <Card className="w-full max-w-md">
      <Card.Header className="gap-3 pb-5">
        <Collapsible.Root defaultOpen className="w-full">
          <Collapsible.Trigger className="flex w-full items-center justify-between text-base font-medium">
            Order #4189
          </Collapsible.Trigger>
          <Collapsible.Content contentClassName="pt-3">
            <Stack gap="2" className="text-sm">
              <Stack direction="row" justify="between" align="center">
                <Text className="text-text-subtle">Status</Text>
                <Text>Shipped</Text>
              </Stack>
              <Text className="text-text-subtle">
                Tracking updates when the carrier scans the package.
              </Text>
            </Stack>
          </Collapsible.Content>
        </Collapsible.Root>
      </Card.Header>
    </Card>
  );
}
```

## Settings panel

Use `Collapsible.Trigger` with Base UI’s `render` prop when a [Button](/components/button/) or other control should own the trigger element. Set `showChevron={false}` when the control already communicates state.

```tsx
import { Button, Collapsible, Field, Input, Stack } from "@zentara-co/zenos-ui";

function CollapsibleSettingsPanelExample() {
  return (
    <Collapsible.Root className="w-full max-w-md">
      <Collapsible.Trigger render={<Button variant="primary" size="sm" />} showChevron={false}>
        Radius
      </Collapsible.Trigger>
      <Collapsible.Content>
        <Stack gap="3" className="pt-3">
          <Field>
            <Field.Label>Radius X</Field.Label>
            <Input defaultValue="8" inputMode="numeric" aria-label="Radius X" />
          </Field>
          <Field>
            <Field.Label>Radius Y</Field.Label>
            <Input defaultValue="8" inputMode="numeric" aria-label="Radius Y" />
          </Field>
        </Stack>
      </Collapsible.Content>
    </Collapsible.Root>
  );
}
```

## File tree

Nested folders and files belong in [File Tree](/components/file-tree/). Collapsible stays the primitive for one disclosure region.

## Controlled state

Use `open` and `onOpenChange` when another part of the UI must read or drive the disclosure. Prefer `defaultOpen` for local, uncontrolled usage.

```tsx
import { Collapsible, Stack, Text } from "@zentara-co/zenos-ui";
import { useState } from "react";

function CollapsibleControlledExample() {
  const [open, setOpen] = useState(false);

  return (
    <Stack gap="3" className="w-full max-w-xl">
      <Collapsible.Root open={open} onOpenChange={setOpen}>
        <Collapsible.Trigger>{open ? "Hide" : "Show"} deployment details</Collapsible.Trigger>
        <Collapsible.Content>
          Production deploys require two approvals and a passing security scan.
        </Collapsible.Content>
      </Collapsible.Root>
      <Text className="text-sm text-text-subtle" aria-live="polite">
        Panel is {open ? "open" : "closed"}.
      </Text>
    </Stack>
  );
}
```

## States

`defaultOpen` sets the initial uncontrolled state. A disabled trigger stays visible but cannot open its panel.

```tsx
import { Collapsible, Stack } from "@zentara-co/zenos-ui";

function CollapsibleStatesExample() {
  return (
    <Stack gap="4" className="w-full max-w-xl">
      <Collapsible.Root>
        <Collapsible.Trigger>Closed by default</Collapsible.Trigger>
        <Collapsible.Content>
          This content appears after the trigger is activated.
        </Collapsible.Content>
      </Collapsible.Root>
      <Collapsible.Root>
        <Collapsible.Trigger disabled>Unavailable section</Collapsible.Trigger>
        <Collapsible.Content>Unavailable content</Collapsible.Content>
      </Collapsible.Root>
    </Stack>
  );
}
```

## Panel variant

When you want the contained shell without wrapping `Card`, set `variant="panel"` on `Root`.

```tsx
import { Collapsible } from "@zentara-co/zenos-ui";

function CollapsiblePanelExample() {
  return (
    <Collapsible.Root variant="panel" defaultOpen className="max-w-xl">
      <Collapsible.Trigger>Advanced settings</Collapsible.Trigger>
      <Collapsible.Content>
        Configure retention, exports, and workspace access policies.
      </Collapsible.Content>
    </Collapsible.Root>
  );
}
```

## Custom styling

Override surfaces with semantic tokens on `Root`, `Trigger`, or `contentClassName`. Panel variant accepts the same accent treatments as before; default variant keeps animation on `Content` while you style the surrounding layout.

```tsx
import { Collapsible } from "@zentara-co/zenos-ui";

function CollapsibleCustomExample() {
  return (
    <Collapsible.Root
      variant="panel"
      defaultOpen
      className="max-w-xl border-border-accent-purple-default bg-background-accent-purple-subtlest-default"
    >
      <Collapsible.Trigger className="text-text-accent-purple-bolder hover:bg-background-accent-purple-subtlest-hover data-[panel-open]:bg-background-accent-purple-subtlest-hover">
        Campaign details
      </Collapsible.Trigger>
      <Collapsible.Content contentClassName="border-border-accent-purple-default text-text-accent-purple-bolder">
        This campaign includes three audiences and runs until the end of the quarter.
      </Collapsible.Content>
    </Collapsible.Root>
  );
}
```

## Collapsible or Accordion

Use Collapsible for one optional region. Use [Accordion](/components/accordion/) when several related sections need heading structure and shared list behavior. Use [File Tree](/components/file-tree/) for nested folders and files.

## Variants

default, panel

## Anatomy

```text
Collapsible.Root
Collapsible.Trigger
Collapsible.Content
```

## API

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| Root.variant | default \| panel | default | Default leaves Root unstyled for Card and layout composition; panel applies the contained disclosure shell. |
| open | boolean | — | Controlled expanded state. |
| defaultOpen | boolean | false | Initial uncontrolled state. |
| onOpenChange | (open: boolean, eventDetails) => void | — | Runs when state changes. |
| Trigger.disabled | boolean | false | Prevents Trigger activation. |
| Trigger.showChevron | boolean | true | Shows the built-in disclosure chevron. |
| Trigger.render | ReactElement \| function | — | Composes Trigger with another element. |
| Content.contentClassName | string | — | Adds classes to the inner content wrapper without changing panel animation. |

Unless narrowed above, each DOM-rendering part also accepts its underlying native or Base UI props, including className, style, aria-*, and data-*.

## Accessibility

The trigger is a native button (or the element passed to `render`) and exposes `aria-expanded`. Enter and Space toggle it when focused. Keep labels meaningful, preserve visible focus, and avoid nesting interactive controls inside the trigger unless they stop propagation. Motion-reduction preferences disable height and chevron transitions.

Source: https://zenos-ui.pages.dev/components/collapsible/