Overview
FAQ / settings accordion that animates height and opacity with { bounce: 0, duration: 0.35 }. Rapid open/close retargets mid-flight — no locked keyframe sequence. Chevron rotation shares the same spring.
Installation
Basic Usage
tsx
import { SpringAccordion } from "@/components/ui/spring-accordion"; <SpringAccordion type="single" defaultValue="a" items={[ { value: "a", title: "Why springs?", children: "They retarget from the live value when interrupted.", }, ]}/>
Props
| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
| items | SpringAccordionItem[] | Yes | — | Panels with value, title, children, optional disabled. |
| type | "single" | "multiple" | No | "single" | One open panel vs many. |
| value | string | string[] | No | — | Controlled open value(s). |
| defaultValue | string | string[] | No | — | Uncontrolled initial open value(s). |
| onValueChange | (value: string | string[]) => void | No | — | Fires when open state changes. |
| className | string | No | — | Optional class names on the root. |
Best Practices
- Use for occasional expands (FAQ, settings) — not high-frequency navigation.
- Keep bounce at zero; overshoot on an accordion feels wrong without a flick.
- Reduced motion collapses to a short opacity/height ease.
- Trigger press uses
scale(0.98)— subtler than primary buttons.