Examples
Related sections
A named section opens in place while the remaining sections stay available without leaving the page.
Accordion with one section open
import {
Accordion,
AccordionContent,
AccordionHeader,
AccordionItem,
AccordionTrigger,
} from "@phuctech/ui/components/accordion";
export function Example() {
return (
<Accordion defaultValue={["overview"]} className="w-full max-w-xl">
<AccordionItem value="overview">
<AccordionHeader>
<AccordionTrigger>Workspace overview</AccordionTrigger>
</AccordionHeader>
<AccordionContent>
See the current members, activity, and shared settings without leaving the workspace.
</AccordionContent>
</AccordionItem>
<AccordionItem value="access">
<AccordionHeader>
<AccordionTrigger>Access and permissions</AccordionTrigger>
</AccordionHeader>
<AccordionContent>
Review who can invite teammates, edit settings, and publish changes.
</AccordionContent>
</AccordionItem>
</Accordion>
);
}
Multiple sections open
Use multiple when people need to compare or work through more than one section at a time.
Accordion with multiple sections open
import {
Accordion,
AccordionContent,
AccordionHeader,
AccordionItem,
AccordionTrigger,
} from "@phuctech/ui/components/accordion";
export function Example() {
return (
<Accordion
multiple
defaultValue={["notifications", "security"]}
className="w-full max-w-xl"
>
<AccordionItem value="notifications">
<AccordionHeader>
<AccordionTrigger>Notifications</AccordionTrigger>
</AccordionHeader>
<AccordionContent>
Weekly summaries are on. Product announcements remain off until you opt in.
</AccordionContent>
</AccordionItem>
<AccordionItem value="security">
<AccordionHeader>
<AccordionTrigger>Security</AccordionTrigger>
</AccordionHeader>
<AccordionContent>
Two-step verification protects all workspace administrator accounts.
</AccordionContent>
</AccordionItem>
</Accordion>
);
}
Controlled open state
Feature state can coordinate the open items while Accordion keeps the disclosure semantics.
Open sections: overview
Controlled Accordion with open sections
"use client";
import { useState } from "react";
import {
Accordion,
AccordionContent,
AccordionHeader,
AccordionItem,
AccordionTrigger,
} from "@phuctech/ui/components/accordion";
export function Example() {
const [openItems, setOpenItems] = useState<string[]>(["overview"]);
return (
<div className="grid w-full max-w-xl gap-3">
<Accordion<string>
multiple
value={openItems}
onValueChange={setOpenItems}
>
<AccordionItem value="overview">
<AccordionHeader>
<AccordionTrigger>Overview</AccordionTrigger>
</AccordionHeader>
<AccordionContent>
The feature owns the open state when another control needs to coordinate with it.
</AccordionContent>
</AccordionItem>
<AccordionItem value="activity">
<AccordionHeader>
<AccordionTrigger>Activity</AccordionTrigger>
</AccordionHeader>
<AccordionContent>
The activity panel follows the same disclosure semantics as the overview panel.
</AccordionContent>
</AccordionItem>
</Accordion>
<p className="text-sm text-muted-foreground">
Open sections: {openItems.length > 0 ? openItems.join(", ") : "none"}
</p>
</div>
);
}
Unavailable section
A section can remain visible while unavailable in the current context.
Accordion with a disabled item
import {
Accordion,
AccordionContent,
AccordionHeader,
AccordionItem,
AccordionTrigger,
} from "@phuctech/ui/components/accordion";
export function Example() {
return (
<Accordion defaultValue={["overview"]} className="w-full max-w-xl">
<AccordionItem value="overview">
<AccordionHeader>
<AccordionTrigger>Workspace overview</AccordionTrigger>
</AccordionHeader>
<AccordionContent>
This section is available and can be opened or closed normally.
</AccordionContent>
</AccordionItem>
<AccordionItem value="billing" disabled>
<AccordionHeader>
<AccordionTrigger>Billing (available on Pro)</AccordionTrigger>
</AccordionHeader>
<AccordionContent>
Upgrade the workspace before changing billing details.
</AccordionContent>
</AccordionItem>
</Accordion>
);
}
Long content
Long supporting content gets its own bounded scroll region instead of clipping the panel or page.
Accordion with a bounded long-content region
import {
Accordion,
AccordionContent,
AccordionHeader,
AccordionItem,
AccordionTrigger,
} from "@phuctech/ui/components/accordion";
const notes = [
"Keep the visible heading short so people can scan the disclosure list.",
"Put the explanation in the panel and let it wrap naturally at narrow widths.",
"Bound unusually long supporting material in its own scroll region.",
"Keep the next action near the content it changes instead of hiding it behind hover.",
"Use multiple when people need to compare sections side by side.",
];
export function Example() {
return (
<Accordion defaultValue={["guidance"]} className="w-full max-w-xl">
<AccordionItem value="guidance">
<AccordionHeader>
<AccordionTrigger>Long-form guidance</AccordionTrigger>
</AccordionHeader>
<AccordionContent>
<div className="scrollbar-hover-reveal max-h-36 overflow-y-auto pr-2">
{notes.map((note) => (
<p key={note} className="mb-3 last:mb-0">
{note}
</p>
))}
</div>
</AccordionContent>
</AccordionItem>
</Accordion>
);
}
When to use
Use Accordion for related sections that people may need to open without leaving the current
page. Keep the headings short and let the panel carry the supporting explanation. Use
multiple when people need to compare sections; use Tabs for peer views where only
one panel should be visible at a time.
Usage
import {
Accordion,
AccordionContent,
AccordionHeader,
AccordionItem,
AccordionTrigger,
} from "@phuctech/ui/components/accordion";
export function Example() {
return (
<Accordion defaultValue={["overview"]} className="w-full max-w-xl">
<AccordionItem value="overview">
<AccordionHeader>
<AccordionTrigger>Workspace overview</AccordionTrigger>
</AccordionHeader>
<AccordionContent>
See the current members, activity, and shared settings without leaving the workspace.
</AccordionContent>
</AccordionItem>
<AccordionItem value="access">
<AccordionHeader>
<AccordionTrigger>Access and permissions</AccordionTrigger>
</AccordionHeader>
<AccordionContent>
Review who can invite teammates, edit settings, and publish changes.
</AccordionContent>
</AccordionItem>
</Accordion>
);
}
Give each AccordionItem a stable value. The root can be uncontrolled
with defaultValue or controlled with value and
onValueChange. Compose the heading, trigger, and content parts in that order.
API
Tokens
Accessibility
- Each trigger is a real button inside a heading, so Enter and Space toggle its panel.
- Keep focus visible and use a heading label that explains the content before it opens.
- Use stable item values and let the primitive connect each trigger to its panel.
- Use
hiddenUntilFoundwhen important closed content should be discoverable through browser find-in-page. - Respect reduced-motion preferences and never make a required instruction available only after expansion.
Do and don’t
Use short, descriptive headings and keep each panel about one related subject.
Hide critical actions, unrelated navigation, or a single short sentence behind an Accordion.
Related
- Tabs keeps peer views visible as one active panel at a time.
- Card provides a surface when the grouped content should stay visible.
- Accessibility documents the shared focus and keyboard review.