Searching Puzzle Pieces

Type to search Puzzle Pieces.

Collapsible

An animated disclosure: a button that expands and collapses a region. It is a compound family that wraps the @magic-spells/collapsible-content web component, so the height measurement, the distance-derived duration, the mid-animation reversal, every ARIA attribute and the reduced-motion branch come from the component rather than from a hand-rolled copy in this file.

Free carbon-neutral 2-day shipping over $75, and 30 days to change your mind. The body is real markup — this paragraph, the list below, or any other component.

  • Same-day dispatch before 2pm ET
  • Return shipping is on us
Two years against manufacturing defects, extended to three if you register within a month.

Installation

Copy the family into your app:

puzzle add piece collapsible

It has one runtime dependency — the web component it wraps:

npm install @magic-spells/collapsible-content

Then merge its stylesheet into your app's style entry. It is required: the height transition the whole animation runs on lives there, along with overflow: hidden, the button reset and the reduced-motion opt-out.

/* app/styles/styles.css */
@import "tailwindcss";
@import "@magic-spells/collapsible-content/css" layer(components); /* required */

Requires the pieces.css tokens merged into your app styles (see Introduction).

Usage

import Collapsible from '@/components/ui/Collapsible';
<Collapsible>
  <Collapsible.Trigger>Shipping and returns</Collapsible.Trigger>
  <Collapsible.Content>
    <p>Real markup — this is not a text prop.</p>
  </Collapsible.Content>
</Collapsible>

The root renders a non-exclusive collapsible-group around the component, and that wrapper is load-bearing: a component joins its nearest group ancestor, so without it a standalone Collapsible dropped inside an Accordion item would be closed by that accordion's exclusivity. Its own plain group shields it.

Starting expanded

Headphones, a braided USB-C cable, a 3.5 mm cable and a hard travel case.

Controlled open

The parent owns this panel's state. Toggling it from the button below is a fresh edge; toggling it from the trigger reports through @change.
open = false

Animation pace

Duration is derived from the distance travelled at this px/sec pace, then clamped — short panels never feel instant and tall ones never crawl.
The same panel at a slower pace, with a custom easing forwarded as --collapsible-easing.

Disabled trigger

A disabled trigger is a real disabled button, so the component's own click listener never fires.

Reference

Collapsible

openOptional-controlled and edge-triggered. Omit it and the component owns its own state, which is the normal case.
classMerged onto the collapsible-group host.
@change(open)Value-first; fired when THIS collapsible toggles. A nested one's bubbling event is filtered out by target.

Collapsible.Trigger

disabledRenders the disabled attribute on the real button, so the component's click listener never fires.
classMerged onto the button, after the chrome. The chevron flips on aria-expanded — pure CSS, no prop.

Collapsible.Content

defaultOpenStart expanded. Initial only — the open attribute is frozen after the first render.
speedpx/sec pace feeding the derived duration (component default 900).
minDurationSeconds; floor for the derived duration (default 0.25).
maxDurationSeconds; ceiling for it (default 0.8).
easingCSS timing function, forwarded as --collapsible-easing.
classMerged onto the panel, after the padding. Never overflow-hidden, a height utility or a transition.

A rejected toggle is not reverted. The component self-manages and then reports; a parent that ignores @change leaves the panel visually open while its own state says closed, and the next real change to open puts it right. Reverting would fight the animation.