Accordion
Accordion
The Accordion component renders a list of expandable question and answer rows: a semibold question on the left, a plus or minus icon on the right, and the answer revealed underneath when the row is open. Rows sit directly on the page background and are separated by hairlines. It powers the FAQ on the Programmable Tokens page and works for any short list of disclosures.
Features
- Accessible toggles - every row is a real
<button>inside an<h3>witharia-expandedandaria-controls; each answer is a labeledrole="region", and a closed answer is hidden from the tab order and from assistive technology - Smooth open and close - answers expand and collapse with a height transition done in CSS (a grid row going from
0frto1fr), with no JavaScript measuring - Answers in the HTML - every answer is rendered, open or closed, so the full text is available to search engines and without JavaScript
- Single-open by default - opening a row closes the others; pass
allowMultipleto keep several open at once - Optional starting state -
defaultOpenIndexopens one row on first render - Rich answers - string arrays support
-bullet lines,[text](url)links, and**bold**, or pass any React node - Dark mode support - text, borders, and icons use theme-aware tokens, and there is no card surface to invert
- Reduced motion - the open and close transition and the hover color change are turned off for users who prefer reduced motion, so rows open instantly
Basic Usage
import Accordion from '@site/src/components/Layout/Accordion';
const items = [
{
question: "What are programmable tokens?",
answer: [
"Native tokens whose transfers have to pass rules set by their issuer, for example:",
"- An allowlist of verified holders",
"- A denylist of sanctioned addresses",
],
},
{
question: "Where can I learn more?",
answer: ["Start with the [programmable token](/glossary/programmable-token) glossary entry."],
},
];
<Accordion items={items} defaultOpenIndex={0} />
Keep the questions and answers in a data module or JSON file wrapped with @docusaurus/Translate, as src/data/programmable-tokens.js does, rather than writing them inline in JSX.