Accordion
import { Accordion, AccordionItem } from "@cherry-design-system/react";
export function Faq() {
return (
<Accordion type="single">
<AccordionItem title="What is cherry?" defaultOpen>
A React design system in plain CSS.
</AccordionItem>
<AccordionItem title="Does it need client JS?">
Only where a component is interactive.
</AccordionItem>
</Accordion>
);
}Accordion stacks collapsible sections, such as FAQ entries or grouped settings. Each AccordionItem is a native <details> / <summary>, so keyboard support, find-in-page and assistive tech work without client JavaScript.
Examples
One open at a time
With type="single" the items share a native name, so opening one closes the others. The default, type="multiple", lets any number stay open.
import { Accordion, AccordionItem } from "@cherry-design-system/react";
export function Shipping() {
return (
<Accordion type="single" name="shipping-faq">
<AccordionItem title="How long does shipping take?">3 to 5 business days.</AccordionItem>
<AccordionItem title="Do you ship abroad?">Yes, to 40 countries.</AccordionItem>
<AccordionItem title="Can I return an order?">Within 30 days.</AccordionItem>
</Accordion>
);
}Inline variant
card draws a bordered surface per item. inline separates items with divider lines. An item can override the variant set on the Accordion.
import { Accordion, AccordionItem } from "@cherry-design-system/react";
export function Settings() {
return (
<Accordion variant="inline">
<AccordionItem title="Notifications">Email and push settings.</AccordionItem>
<AccordionItem title="Privacy">Who can see your profile.</AccordionItem>
</Accordion>
);
}Controlled item
AccordionItem passes native <details> attributes through, so use open with onToggle to control it.
"use client";
import { useState } from "react";
import { AccordionItem } from "@cherry-design-system/react";
export function ControlledItem() {
const [open, setOpen] = useState(false);
return (
<AccordionItem
title="Advanced options"
open={open}
onToggle={(event) => setOpen(event.currentTarget.open)}
>
Cache size, log level and experimental flags.
</AccordionItem>
);
}Properties
Accordion
Applied to every item that does not set its own. Defaults to "card".
single lets one item open at a time (items share a native name); multiple lets any number open. Defaults to "multiple".
The group name used by type="single". Generated when omitted.
The AccordionItems.
Accordion renders a <div>, forwards its ref to it and passes every other <div> attribute through.
AccordionItem
The always-visible heading, rendered in the <summary>.
card (bordered surface) or inline (divider lines). Defaults to "card", or to the Accordion's variant.
Starts open (uncontrolled). Use open and onToggle for controlled use.
AccordionItem renders a <details>, forwards its ref to it and passes every other <details> attribute through. Neither part has client JavaScript, so both are safe in Server Components.
Styling
| Hook | Values |
|---|---|
.cherry-accordion | Root element |
data-variant | card, inline |
[open] | An open item |
| Parts | .cherry-accordion__item, __trigger, __title, __chevron, __body |
Items read --cherry-border-default, --cherry-bg-canvas and --cherry-radius-lg; the title uses the label-md text tokens and the body the body-sm text tokens.
Accessibility
Native <details> / <summary>: Enter or Space toggles an item and the open state is announced natively. type="single" keeps one item open through the native exclusive accordion.