Keyframery

Collapsible

Content opens to its real height on a spring and its rows fall in one after another.

See it as an AI agent does.

Resize preview. Focus the handle and use the left or right arrow keys. Hold Shift for larger steps.— px
Customize1 controls
Animation speed1×

Installation

npx shadcn@latest add @keyframery/collapsible

This adds components/keyframery/collapsible.tsx and its primitive to your project, and installs UI SDK. The motion tokens are added to your global CSS the first time you install a component.

Usage

import { Collapsible, CollapsiblePanel, CollapsibleTrigger } from "@/components/keyframery/collapsible"

export default function Usage() {
  return (
    <Collapsible>
      <CollapsibleTrigger>Show details</CollapsibleTrigger>
      <CollapsiblePanel>The details.</CollapsiblePanel>
    </Collapsible>
  )
}

Anatomy

How the parts fit together:

Collapsible
├── CollapsibleTrigger
└── CollapsiblePanel

Examples

Basic

The panel opens to its real height. The trigger's text can follow the state.

Controlled

Pass open and onOpenChange to open it from elsewhere.

Motion

MoveWhat you see
HeightContent opens to its real height.
CascadeIts rows fall in one after another.
SpringThe chevron turns on a spring.

Timing and springiness follow the motion style you set. To change how fast this collapsible moves, pass speed:

<Collapsible speed="fast">
  …
</Collapsible>

"fast" is 0.6×, "slow" 1.4×, and a number sets the multiplier. With reduced motion turned on, nothing moves: changes happen at once or with a short fade.

Theming

Set these CSS variables on the component or a parent. Leave them unset to follow the light and dark theme. The open Customize panel below the preview lets you try these settings.

VariableWhat it changesDefault
--collapsible-heightTrigger height2.25rem
--collapsible-gapLabel and chevron gap0.75rem
--collapsible-radiusTrigger corners9px
--collapsible-fontTrigger label size13px
--collapsible-faceTrigger surfacetransparent; hover --foreground 4.5%; pressed --foreground 7%
--collapsible-mutedResting trigger text--muted-foreground
--collapsible-inkOpen and hovered trigger text--foreground

API reference

Every part takes className and children. Parts from UI SDK also take render, to draw your own element, and a function of their state for className and style. Props not listed here are in the UI SDK collapsible reference.

Collapsible

Renders a <div>, and takes its props too.

Prop

Type

CollapsiblePanel

Renders a <div>, and takes its props too.

Prop

Type

Other parts

These take the props of the element they render, and nothing else:

  • CollapsibleTrigger: a <button>

Keyboard

KeyWhat it does
EnterOpens or closes the panel.
SpaceOpens or closes the panel.

Accessibility

Keyboard, focus and screen-reader behaviour come from UI SDK and are not changed. More in Accessibility.

Swap the import

Already using UI SDK's collapsible with your own styles? Keep your markup and change one line. The primitive adds motion and nothing else.

// Before
import { … } from "@ui-sdk/react/collapsible"

// After: same parts, same props, now animated
import { … } from "@/components/keyframery/primitives/collapsible"

Questions

How does the animated Collapsible for UI SDK move?

Height: Content opens to its real height. Cascade: Its rows fall in one after another. Spring: The chevron turns on a spring.

Do I need Motion or Framer Motion for the animated Collapsible?

No. Every move is plain CSS, so there is nothing to install besides the component and UI SDK.

Can I keep my own styling and only take the motion?

Yes. Import from @/components/keyframery/primitives/collapsible instead. It has the same parts and props as @ui-sdk/react/collapsible and adds motion only.

What happens to the Collapsible when someone turns on reduced motion?

Nothing moves. State changes happen at once, or with a short fade.

All components

On this page