Accordion
Reveal and hide related sections of content.
Overview
Accordion reveals optional related sections without leaving the current page. Its named parts pair each heading button with one retained content region.
Use when
Related, optional sections can be revealed on demand without hiding essential information.
Use instead
Use headings and visible content when readers need to compare all sections at once.
Usage
import {
Accordion,
AccordionBody,
AccordionContent,
AccordionItem,
AccordionTrigger,
} from "@smoothie-framework/whisk-react";
<Accordion type="single" defaultValue="billing">
<AccordionItem value="billing">
<AccordionTrigger headingLevel={2}>Billing</AccordionTrigger>
<AccordionContent>
<AccordionBody>Invoices and payment methods.</AccordionBody>
</AccordionContent>
</AccordionItem>
</Accordion>Examples
Keep one section open
Single selection is the default. With collapsible unset, the open section stays open, which works well when one detail section should always remain visible.
import {
Accordion,
AccordionBody,
AccordionContent,
AccordionItem,
AccordionTrigger,
} from "@smoothie-framework/whisk-react";
<Accordion defaultValue="shipping">
<AccordionItem value="shipping">
<AccordionTrigger headingLevel={2}>Shipping</AccordionTrigger>
<AccordionContent><AccordionBody>Delivery options and tracking.</AccordionBody></AccordionContent>
</AccordionItem>
<AccordionItem value="returns">
<AccordionTrigger headingLevel={2}>Returns</AccordionTrigger>
<AccordionContent><AccordionBody>Return eligibility and refund timing.</AccordionBody></AccordionContent>
</AccordionItem>
</Accordion>Let every section close
Set collapsible in single mode when no open section is also a valid state. The callback receives an empty string after the open item closes.
import {
Accordion,
AccordionBody,
AccordionContent,
AccordionItem,
AccordionTrigger,
} from "@smoothie-framework/whisk-react";
<Accordion type="single" collapsible defaultValue="security">
<AccordionItem value="security">
<AccordionTrigger headingLevel={2}>Security</AccordionTrigger>
<AccordionContent><AccordionBody>Manage sign-in protection.</AccordionBody></AccordionContent>
</AccordionItem>
</Accordion>Open several related sections
Use type="multiple" when sections are independently useful. Multiple mode always permits closing, so it does not accept collapsible.
import {
Accordion,
AccordionBody,
AccordionContent,
AccordionItem,
AccordionTrigger,
} from "@smoothie-framework/whisk-react";
<Accordion type="multiple" defaultValue={["notifications", "billing"]}>
<AccordionItem value="notifications">
<AccordionTrigger headingLevel={2}>Notifications</AccordionTrigger>
<AccordionContent><AccordionBody>Choose which updates to receive.</AccordionBody></AccordionContent>
</AccordionItem>
<AccordionItem value="billing">
<AccordionTrigger headingLevel={2}>Billing</AccordionTrigger>
<AccordionContent><AccordionBody>View invoices and payment methods.</AccordionBody></AccordionContent>
</AccordionItem>
</Accordion>Control the open item from application state
Use value with onValueChange when another part of the application owns the selection. The callback requests a change; update value to accept it. Do not also pass defaultValue.
import {
Accordion,
AccordionBody,
AccordionContent,
AccordionItem,
AccordionTrigger,
} from "@smoothie-framework/whisk-react";
type SettingsAccordionProps = {
openSection: string;
onOpenSectionChange: (value: string) => void;
};
export function SettingsAccordion({
openSection,
onOpenSectionChange,
}: SettingsAccordionProps) {
return (
<Accordion value={openSection} onValueChange={onOpenSectionChange}>
<AccordionItem value="profile">
<AccordionTrigger headingLevel={2}>Profile</AccordionTrigger>
<AccordionContent><AccordionBody>Profile settings</AccordionBody></AccordionContent>
</AccordionItem>
<AccordionItem value="security">
<AccordionTrigger headingLevel={2}>Security</AccordionTrigger>
<AccordionContent><AccordionBody>Security settings</AccordionBody></AccordionContent>
</AccordionItem>
</Accordion>
);
}Use the built-in panel structure
AccordionContent remains mounted while it is closed so height animation can be measured. Put padding and the panel surface in AccordionBody rather than on AccordionContent.
import {
Accordion,
AccordionBody,
AccordionContent,
AccordionItem,
AccordionTrigger,
} from "@smoothie-framework/whisk-react";
<Accordion type="single" collapsible>
<AccordionItem id="support" value="support">
<AccordionTrigger headingLevel={2} indicator={null}>
Contact support
</AccordionTrigger>
<AccordionContent>
<AccordionBody>Support is available Monday to Friday.</AccordionBody>
</AccordionContent>
</AccordionItem>
</Accordion>Props
Component props
Accessibility
AccordionTrigger renders a native button inside the heading selected by headingLevel. AccordionContent is a labelled region connected to its trigger, so do not manually recreate those ARIA relationships. Enter and Space activate the focused trigger; Arrow keys, Home, and End move focus among available triggers. Decorative start elements and indicators are hidden from assistive technology. Closed panels remain mounted, and reduced-motion users do not receive the height animation. Keep essential information outside collapsed panels when people need to compare it or find it quickly.
Content guidance
Write each trigger as the topic it reveals. Keep essential information out of collapsed panels when readers need to compare it.