FAQ accordion
FAQ accordion
Questions on fine lines that open like they mean it: the answer eases to its height, the plus folds into a minus.
Dependencies
Interaction states
- closed — The question at 80% ink on a thin line, with a plus; hover brings it to full.
- opening — The answer’s row grows to its real height (460ms) and its text rises 6px out of a 4px blur; the plus turns 180° into a minus.
- closing — The words fade in 160ms, then the space closes, so text never gets squeezed.
- single / multiple — One open at a time, or any number.
Installation
Add this component with your preferred package manager.
pnpm dlx shadcn@4.21.5 add @cavemio/faq-accordionFirst install? Configure @cavemio once
Run npx shadcn@4.21.5 init if shadcn is not set up, then merge this entry into the registries field in your existing components.json. Keep your other settings and registries.
{
"registries": {
"@cavemio": "https://registry.cavemio.dev/r/cavemio-{name}.json"
}
}Where it’s used
Landing page FAQs
The questions that stop visitors from signing up, answered in place.
Pricing page questions
Billing, refunds and plan limits next to the plans.
Help centres and docs
Short answers that expand without leaving the page.
Product and checkout pages
Shipping, returns and licence questions where people decide.
What it handles
- It opens to the real height — The answer eases open to its own height, whatever its length, without measuring it first.
- It closes without squeezing — The words fade first and then the space closes, so the text is never crushed.
- One at a time, or many — In single mode, opening one question closes the other in the same motion. Choose which start open.
- Answers can be anything — Text, links, lists or small tables. An answer is any React.
- Keyboard navigation — Up and Down move between questions, and Home and End jump to the first and last.
- Correct markup — Each question is a heading with a button that has aria-expanded, and closed answers are out of the tab order.
Usage
Interactive local fixture. Data and async results are simulated in the preview; the caller supplies application services.
import { FaqAccordion } from "@/components/faq-accordion";
<FaqAccordion
defaultOpen={[0]}
items={[{ question: "Can I use it for client work?", answer: "Yes, one licence covers it." }]}
/>Props
| Prop | Type | Description |
|---|---|---|
| items | { question; answer; id? }[] | – · Each question, and its answer as text or any React. |
| type | "single" | "multiple" | "single" · One answer open at a time, or any number. |
| defaultOpen | number[] | [] · Questions open at first, by index. |
Accessibility & motion
- Each question is a heading with a button (aria-expanded, aria-controls); each answer is a labelled region, hidden from the tab order when closed. - Up and Down move between questions, Home and End jump to the first and last, as the ARIA accordion pattern describes. - Height is animated with grid rows, so answers can be any length without measuring. - With reduced motion, answers open and close in place.
pnpm dlx shadcn@4.21.5 add @cavemio/faq-accordion