nook
Browse the docs

Components

Collapsible

Built on Base UI

A single disclosure with an animated panel and a keyboard-operable trigger.

See the prompt

Installation

npx nook-ui@latest add collapsible

Prompt

Paste this into your AI coding assistant. It adds this exact component, the same way the CLI does, and tells the assistant how to use it.

Short. For assistants that can run commands in your project.

Plain text
Add the Nook "Collapsible" component to this project, exactly as Nook ships it.

A single disclosure with an animated panel and a keyboard-operable trigger.

Steps
1. Check for `nook.json` in the project root. If it is missing, run `npx nook-ui@latest init` first (React or Next.js with Tailwind CSS v4). It adds the Nook tokens, the theme and `cn()`.
2. Run `npx nook-ui@latest add collapsible`. It writes `components/ui/collapsible.tsx` together with everything the component needs. Do not write the component from memory.
3. If you cannot run commands, fetch http://localhost:3000/r/collapsible.json, write every entry of `files` to the path it names, install the packages in `dependencies`, and repeat for each name in `registryDependencies`.
4. Use it where I ask. Start from this example:

```tsx
import {
  Collapsible,
  CollapsibleContent,
  CollapsibleTrigger,
} from "@/components/ui/collapsible";
export default function Example() {
  return (
    <Collapsible className="w-full max-w-md rounded-lg border-(length:--edge) border-(--surface-edge) bg-card p-2">
      <CollapsibleTrigger>Advanced delivery options</CollapsibleTrigger>
      <CollapsibleContent>
        <div className="grid gap-3 px-inset-sm pb-3 text-muted-foreground">
          <p>Deliveries arrive Monday to Friday, between 9 am and 6 pm.</p>
          <p>
            For a loading dock or reception desk, add instructions at checkout.
            We will include them on the shipping label.
          </p>
        </div>
      </CollapsibleContent>
    </Collapsible>
  );
}
```

API
- `Collapsible`: A single disclosure with an animated panel and a keyboard-operable trigger.
  - `open / defaultOpen` (`boolean`): Controlled or initial expanded state.
  - `onOpenChange` (`(open: boolean) => void`): Receives expanded state changes.

Rules
- Colors, radii, shadows and motion come from Nook tokens and classes such as `bg-primary`, `text-muted-foreground`, `border-border`, `rounded-lg` and `h-control`. Never hard-code them.
- Do not restyle or simplify the file. Change how it looks through `className`, its props and the theme.
- It must keep working with the keyboard, in light and dark mode, and in the sharp, soft and bold styles.
- Accessibility: Base UI connects expanded state and the panel; respects reduced motion.

Done when the component renders like the example in light and dark mode and the project type-checks.

Usage

import {
  Collapsible,
  CollapsibleContent,
  CollapsibleTrigger,
} from "@/components/ui/collapsible";
export default function Example() {
  return (
    <Collapsible className="w-full max-w-md rounded-lg border-(length:--edge) border-(--surface-edge) bg-card p-2">
      <CollapsibleTrigger>Advanced delivery options</CollapsibleTrigger>
      <CollapsibleContent>
        <div className="grid gap-3 px-inset-sm pb-3 text-muted-foreground">
          <p>Deliveries arrive Monday to Friday, between 9 am and 6 pm.</p>
          <p>
            For a loading dock or reception desk, add instructions at checkout.
            We will include them on the shipping label.
          </p>
        </div>
      </CollapsibleContent>
    </Collapsible>
  );
}

Examples

Show more

Ana Souza, Kofi Mensah, Priya Nair

Open by default

  • Status: Open
  • Assignee: Me

Disabled

Nested

index.ts

Props

Collapsible

A single disclosure with an animated panel and a keyboard-operable trigger.

PropTypeDefaultDescription
open / defaultOpenboolean–Controlled or initial expanded state.
onOpenChange(open: boolean) => void–Receives expanded state changes.

Accessibility

Base UI connects expanded state and the panel; respects reduced motion.

Checked against WCAG 2.1 AA with automated axe tests and keyboard tests on every release.