# Collapsible

- **[Atoms](/components/)**

One button that shows or hides extra content below it.

## When to use

- **Use for**: One optional region the person can open: a policy, advanced options.
- **Not for**: A list of regions. Use Accordion.
- **Pairs with**: Text, Field, Card.

## Preview

collapsible.tsx

```
import { Theme } from '@/components/klarhimmel/theme/style';
import { Collapsible } from '@/components/klarhimmel/ui/collapsible';

export default function Example() {
  return (
    <Theme theme="brand">
      <Collapsible title="Show the cancellation policy">
        Free until 48 hours before arrival.
      </Collapsible>
    </Theme>
  );
}
```

## Import

- **CLI**

  ```
  npx shadcn add @klarhimmel/collapsible
  ```
- **Import**

  ```
  import { Collapsible } from '@/components/klarhimmel/ui/collapsible';
  ```

- **Files**: collapsible.tsx, in components/klarhimmel/ui/. With it: theme, utils. npm: lucide-react.
- **Render in**: Render it inside <Theme>, once near the root of your app. Tokens and fonts are scoped to it, so outside it the component is unstyled.

## Examples

- **Controlled**

  ```
  import { useState } from 'react';
  import { Button } from '@/components/klarhimmel/ui/button';
  import { Collapsible } from '@/components/klarhimmel/ui/collapsible';
  
  export default function CollapsibleControlled() {
    const [open, setOpen] = useState(true);
    return (
      <div className="flex w-[min(28rem,calc(100cqw-3rem))] flex-col items-start gap-3">
        <Collapsible title="Filters" open={open} onOpenChange={setOpen}>
          <p>Price, rooms, dates and distance to the beach.</p>
        </Collapsible>
        <Button variant="ghost" size="sm" onClick={() => setOpen((o) => !o)}>{open ? 'Hide from outside' : 'Show from outside'}</Button>
      </div>
    );
  }
  ```
- **Disabled**

  ```
  import { Collapsible } from '@/components/klarhimmel/ui/collapsible';
  
  export default function CollapsibleDisabled() {
    return (
      <div className="flex w-[min(28rem,calc(100cqw-3rem))] flex-col gap-3">
        <Collapsible title="Open from the start" defaultOpen>Shown, and it can be hidden.</Collapsible>
        <Collapsible title="Not available while booking is closed" disabled>Hidden.</Collapsible>
      </div>
    );
  }
  ```

## Props

- **title**: The always-visible line that opens and closes the rest.
- **children**
- **open**: Controlled or uncontrolled state.
- **defaultOpen**: Controlled or uncontrolled state.
- **onOpenChange**: Controlled or uncontrolled state.
- **disabled**: The button does nothing.
- **className**: Extra classes, merged after the component's own.

## Accessibility

- Enter / Space · Opens or closes the region
- Tab · Moves focus; the ring is always visible

[Accessibility](/get-started/accessibility)

[Previous](/components/accordion)

[Next](/components/breadcrumb)
