Skip to content
Drivn logoDrivn

Collapsible

Toggle content visibility with smooth animation and accessible controls.

Preview

@drivn/ui has 3 packages

@drivn/components
@drivn/cli
@drivn/mcp

Installation

npx drivn add collapsible

Usage

1import { Collapsible } from "@/components/ui/collapsible"
2import { ChevronsUpDown } from "lucide-react"
3
4export default function Page() {
5 return (
6 <Collapsible className="space-y-2">
7 <div className="flex items-center justify-between">
8 <h4 className="text-sm font-semibold">
9 3 items
10 </h4>
11 <Collapsible.Trigger>
12 <ChevronsUpDown className="w-4 h-4" />
13 </Collapsible.Trigger>
14 </div>
15 <div className="rounded-md border px-4 py-2.5 text-sm">
16 Always visible item
17 </div>
18 <Collapsible.Content className="space-y-2">
19 <div className="rounded-md border px-4 py-2.5 text-sm">
20 Hidden item 1
21 </div>
22 <div className="rounded-md border px-4 py-2.5 text-sm">
23 Hidden item 2
24 </div>
25 </Collapsible.Content>
26 </Collapsible>
27 )
28}

Default Open

Start with content visible using the defaultOpen prop.

@drivn/ui has 3 packages

@drivn/components
@drivn/cli
@drivn/mcp

Controlled

Drive open state with external useState.

3 pinned dependencies

react@19.1.0
next@16.1.6
typescript@5.8.3

File Tree

Nested collapsibles composing a file explorer.

page.tsx
layout.tsx
page.tsx
layout.tsx
globals.css
button.tsx
collapsible.tsx
dialog.tsx
header.tsx
footer.tsx
utils.ts
cn.ts
favicon.ico
og-image.png
next.config.ts
package.json
tsconfig.json

Settings

Collapsible settings sections with icons.

Manage your notification preferences and choose which alerts you want to receive.

Control your privacy settings and manage how your data is shared.

Customize the look and feel, including theme, font size, and layout density.

API Reference

Collapsible

PropTypeDefaultDescription
defaultOpenbooleanfalseInitial open state for uncontrolled mode.
openbooleanControlled open state. Use with onOpenChange.
onOpenChange(open: boolean) => voidCallback fired when the open state changes.
classNamestringAdditional CSS classes for the root element.
childrenReactNodeTrigger and Content sub-components.

Collapsible.Trigger

PropTypeDefaultDescription
childrenReactNodeTrigger label content.
classNamestringAdditional CSS classes to apply.
...propsButtonHTMLAttributes<HTMLButtonElement>All standard HTML button attributes are supported.

Collapsible.Content

PropTypeDefaultDescription
childrenReactNodeCollapsible content.
classNamestringAdditional CSS classes to apply.