import { Accordion } from "@senvenli/react/navigation";
export default function Example() {
return (
<Accordion
defaultExpandedKeys={["plans"]}
items={[
{ id: "plans", title: "Can I change plans later?", content: "Yes. Upgrade or downgrade at any time; the price is adjusted on your next invoice." },
{ id: "trial", title: "Is there a free trial?", content: "Every plan starts with 14 days free. No card is needed until the trial ends." },
{ id: "invoices", title: "Where do I find my invoices?", content: "Under Settings, then Billing. Each invoice is also emailed to the billing contact." },
]}
/>
);
}import { Accordion, Disclosure } from "@senvenli/react/navigation";Examples
Several open at once
For sections people compare; some start expanded.import { DescriptionList } from "@senvenli/react/display";
import { Accordion } from "@senvenli/react/navigation";
export default function Example() {
return (
<Accordion
allowsMultipleExpanded
headingLevel={4}
defaultExpandedKeys={["customer", "payment"]}
items={[
{
id: "customer",
title: "Customer",
content: <DescriptionList items={[{ label: "Name", value: "Ada Lovelace" }, { label: "Email", value: "ada@example.com" }]} />,
},
{
id: "payment",
title: "Payment",
content: <DescriptionList items={[{ label: "Method", value: "Card ending 4242" }, { label: "Total", value: "$248.00" }]} />,
},
{ id: "notes", title: "Notes", content: "Prefers delivery before noon." },
]}
/>
);
}Composed from Disclosures
`Disclosure` children with an `id` each: a section can hold anything, here a list and a link.import { Link } from "@senvenli/react/action";
import { Text } from "@senvenli/react/display";
import { Accordion, Disclosure } from "@senvenli/react/navigation";
export default function Example() {
return (
<Accordion defaultExpandedKeys={["shipping"]}>
<Disclosure id="shipping" title="How long does shipping take?">
<ul className="m-0 flex list-disc flex-col gap-ds-050 ps-ds-300">
<li>Standard: 3 to 5 working days</li>
<li>Express: next working day, ordered before 2 pm</li>
</ul>
</Disclosure>
<Disclosure id="returns" title="Can I return an order?">
<Text>
Within 30 days, unused and in its box. <Link href="#returns">Start a return</Link>
</Text>
</Disclosure>
<Disclosure id="contact" title="How do I reach support?">
<Text>Write to us from the Help page; we answer within one working day.</Text>
</Disclosure>
</Accordion>
);
}A single Disclosure
One expandable section on its own, here controlled.import { Text } from "@senvenli/react/display";
import { Stack } from "@senvenli/react/layout";
import { Disclosure } from "@senvenli/react/navigation";
import { useState } from "react";
export default function Example() {
const [isExpanded, setIsExpanded] = useState(false);
return (
<Stack space="space-100">
<Disclosure title="Advanced settings" isExpanded={isExpanded} onExpandedChange={setIsExpanded}>
Requests time out after 30 seconds and are retried three times.
</Disclosure>
<Text size="body-small" tone="subtle">
The section is {isExpanded ? "open" : "closed"}.
</Text>
</Stack>
);
}Guidelines
When to use it
- Long content people scan by heading, like an FAQ.
Accessibility
Keyboard
| Keys | What happens |
|---|---|
| Enter, Space | Expands or collapses a section. |
Built in
- Each header is a button with aria-expanded inside a heading.
You provide
- A heading level that fits the page.
- With children: an id on every Disclosure inside an Accordion (expandedKeys uses it).
API reference
Accordion
| Prop | Type | Default | Description |
|---|---|---|---|
items | readonly AccordionItem[] | – | FAQ entries, settings groups, long-form sections. Leave it out to compose |
children | React.ReactNode | – | With no |
expandedKeys | Iterable<Key> | – | |
defaultExpandedKeys | Iterable<Key> | – | |
onExpandedChange | (keys: Set<Key>) => void | – | |
allowsMultipleExpanded | boolean | – | Several open at once; by default opening one closes the others. |
headingLevel | 4 | 2 | 3 | 5 | 6 | – | |
motion | ComponentMotion | – |
|
itemsreadonly AccordionItem[]FAQ entries, settings groups, long-form sections. Leave it out to compose
Disclosures as children instead.childrenReact.ReactNodeWith no
items:Disclosures, each with anid(the keyexpandedKeysuses).expandedKeysIterable<Key>defaultExpandedKeysIterable<Key>onExpandedChange(keys: Set<Key>) => voidallowsMultipleExpandedbooleanSeveral open at once; by default opening one closes the others.
headingLevel4 | 2 | 3 | 5 | 6motionComponentMotionauto(follow the device),reduceornone, for this component; the provider's setting otherwise.
Disclosure
| Prop | Type | Default | Description |
|---|---|---|---|
titleRequired | React.ReactNode | – | A full question or a clear section name ("When is my deposit refunded?"). |
childrenRequired | React.ReactNode | – | |
isExpanded | boolean | – | |
defaultExpanded | boolean | – | |
onExpandedChange | (isExpanded: boolean) => void | – | |
headingLevel | 4 | 2 | 3 | 5 | 6 | – | The heading level of the title in the page outline; the Accordion's, or 3 by default. |
id | Key | – | Inside an Accordion: its key. |
motion | ComponentMotion | – |
|
titleRequiredReact.ReactNodeA full question or a clear section name ("When is my deposit refunded?").
childrenRequiredReact.ReactNodeisExpandedbooleandefaultExpandedbooleanonExpandedChange(isExpanded: boolean) => voidheadingLevel4 | 2 | 3 | 5 | 6The heading level of the title in the page outline; the Accordion's, or 3 by default.
idKeyInside an Accordion: its key.
motionComponentMotionauto(follow the device),reduceornone, for this component; the provider's setting otherwise.