cnippet/ui
  1. ui
  2. data
  3. collapsible

data

Collapsible

A collapsible panel controlled by a button. Built with Base UI and Tailwind CSS. Copy-paste ready.

API Reference

Installation

Usage

Anatomy

Good to know

  • The state props are open, defaultOpen and onOpenChange.
  • CollapsibleTrigger only adds cursor-pointer. To make it look like a button, use render={<Button variant="ghost" />}. There is no asChild.
  • CollapsibleContent is an alias of CollapsiblePanel. Prefer CollapsiblePanel.
  • The open/close animation uses the --collapsible-panel-height CSS variable. Don't add your own height transition.
  • For several sections where the open state is managed together, use Accordion instead.

API Reference

Collapsible

Root container. Thin wrapper around Base UI's Collapsible.Root.

CollapsibleTrigger

The element that toggles the panel open and closed.

CollapsiblePanel

The collapsible content area. Also exported as CollapsibleContent. Animates height via CSS transition.

Examples

Default

A minimal trigger-and-panel pair — clicking the trigger toggles the panel's visibility with a smooth height animation.

Animated Card

The collapsible is styled as a card with a header trigger and an animated content area that slides open and closed.

Bottom Trigger

Places the expand trigger at the bottom of the card — useful for "show more" patterns below a content preview.

Form Fields

Hides advanced or optional form fields behind a collapsible to keep the form compact until the user needs them.

Multi-level Menu

A sidebar-style navigation where each section header is a collapsible trigger that reveals nested menu items.

Tree View

A file-tree implementation where directories are collapsible nodes and each item exposes hover actions for rename, copy, and delete.

Read More

A product description card with truncated text and a gradient fade overlay. A "Read more" / "Show less" trigger with a rotating chevron expands and collapses the full content.

Build Log

Three pipeline step cards (install / typecheck / build) showing a status badge. Clicking a completed step expands a syntax-colored pre log panel. Pending steps are disabled.

Incident Timeline

An always-visible incident summary with a "View incident timeline" trigger that expands a vertical dot-and-line timeline with status badges and timestamps.

FAQ Accordion

Four questions rendered as individual Collapsible components with single-open behavior — opening one automatically closes the others. A badge shows total question count.

Filter Panel

A sidebar filter panel where each filter group (Category, Status, Priority) is a collapsible section with checkboxes. An active-count badge and a clear-all button update as filters are toggled.

Package Dependencies

Three package groups (Middleware, Security, UI) rendered as cards with a version badge trigger. Expanding a card reveals a description and a list of package names in monospace.

Team Directory

A sidebar-style list of teams where each section is collapsible. Members show a colored presence dot, their name, and role beneath the team header.

Privacy Policy

A card with four policy sections rendered as accordion-style collapsibles. Only one section is open at a time, driven by controlled open state.