When to use
- Questions and answers where people scan the questions and open one or two: an FAQ, a billing help panel.
- Secondary detail under a heading that most people skip: shipping terms on a product page, advanced settings.
- Long sections in a narrow column, where showing everything at once would push the useful part off screen.
When not to use
- Views of one thing that replace each other in the same place: use Tabs.
- Content people need to compare side by side or read in order: put it on the page.
- Steps someone must complete in sequence: a disclosure hides the next step instead of guiding them to it.
Installation
pnpm dlx shadcn add https://eased.dev/r/accordion.jsonnpx shadcn add https://eased.dev/r/accordion.jsonyarn dlx shadcn add https://eased.dev/r/accordion.jsonbunx --bun shadcn add https://eased.dev/r/accordion.jsonThe command adds Accordion, everything it builds on and Eased’s tokens to your project.
Install the dependencies
pnpm add @base-ui/reactnpm install @base-ui/reactyarn add @base-ui/reactbun add @base-ui/reactAdd the Eased pieces it builds on
Copy each item’s files the same way, or install them with the CLI:
Copy the source into your project
components/eased/accordion/accordion.tsxTSX "use client";import { Accordion as BaseAccordion } from "@base-ui/react/accordion";import { useState, type HTMLProps, type ReactNode } from "react";import { AutoHeight } from "../_primitives/auto-height/auto-height";export type AccordionProps<V extends string> = { /** Open items (controlled). */ value?: V[]; /** Initially open items (uncontrolled). */ defaultValue?: V[]; onValueChange?: (value: V[]) => void; /** Allow more than one item open at a time. Default `false`. */ multiple?: boolean; disabled?: boolean; className?: string; children: ReactNode;};/** * A stack of disclosures separated by hairlines. Base UI's Accordion supplies the * behaviour: buttons in headings, `aria-expanded`/`aria-controls`, Enter and Space to * toggle. Tab moves between triggers (in Base UI 1.9 arrow keys do not). */export function Accordion<V extends string>({ className = "", onValueChange, children, ...props }: AccordionProps<V>) { return ( <BaseAccordion.Root<V> {...props} onValueChange={(v) => onValueChange?.(v)} className={`flex min-w-0 flex-col divide-y divide-line-subtle ${className}`} > {children} </BaseAccordion.Root> );}export type AccordionItemProps<V extends string> = { value: V; /** The trigger's label. */ title: ReactNode; /** Heading level of the trigger, so it fits the page outline. Default 3. */ headingLevel?: 2 | 3 | 4 | 5 | 6; disabled?: boolean; /** The panel's content. */ children: ReactNode; className?: string;};function Chevron() { return ( <svg viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth={1.5} strokeLinecap="round" strokeLinejoin="round" aria-hidden className="size-4 shrink-0 text-text-muted [transition:rotate_var(--eased-duration-spring-smooth)_var(--eased-spring-smooth),color_150ms_var(--eased-ease-standard)] group-data-panel-open:rotate-180 reduced:[transition:none]" > <path d="m4 6.5 4 4 4-4" /> </svg> );}/** * Base UI hides a closing panel at once; this keeps it rendered until AutoHeight has * finished collapsing it, then hides it so the empty region leaves the accessibility tree. */function PanelBody({ open, htmlProps }: { open: boolean; htmlProps: HTMLProps<HTMLDivElement> }) { const [collapsed, setCollapsed] = useState(!open); const { hidden, children, ...rest } = htmlProps; void hidden; return ( <div {...rest} hidden={!open && collapsed}> <AutoHeight open={open} onOpenChangeComplete={(isOpen) => setCollapsed(!isOpen)} innerClassName="pb-4 text-ui text-text-secondary text-pretty" > {children} </AutoHeight> </div> );}/** * One item. Its height springs open with no overshoot, the content fades in as the height * lands, and the chevron turns on the same spring. Closing fades the content first and is * quicker than opening. */export function AccordionItem<V extends string>({ value, title, headingLevel = 3, disabled, children, className = "",}: AccordionItemProps<V>) { const H = `h${headingLevel}` as const; return ( <BaseAccordion.Item value={value} disabled={disabled} className={`min-w-0 ${className}`}> <BaseAccordion.Header render={<H />} className="m-0"> <BaseAccordion.Trigger className={(state) => `group flex w-full items-center justify-between gap-3 rounded-control-xs py-3 text-left text-ui font-medium focus-ring ${ state.disabled ? "cursor-not-allowed text-text-disabled" : "cursor-pointer text-text hover-fine:[&_svg]:text-text-secondary" }` } > <span className="min-w-0 text-balance">{title}</span> <Chevron /> </BaseAccordion.Trigger> </BaseAccordion.Header> <BaseAccordion.Panel keepMounted // Base UI owns open state and ARIA; AutoHeight owns the motion. render={(htmlProps, state) => <PanelBody open={state.open} htmlProps={htmlProps} />} > {children} </BaseAccordion.Panel> </BaseAccordion.Item> );}Keep the folder layout
The files import each other by relative path (
../lib/motion), so keep each one at the path shown, undercomponents/eased/.
Usage
import { Accordion, AccordionItem } from "@/components/eased/accordion/accordion";export function BillingFaq() { return ( <Accordion defaultValue={["charged"]}> <AccordionItem value="charged" title="When am I charged?"> On the day your trial ends, then on the same date every month. </AccordionItem> <AccordionItem value="refund" title="Do you offer refunds?"> Within 14 days of any charge, in full. </AccordionItem> </Accordion> );}Examples
Several open at once
Pass multiple when people open items to compare them, such as plan details.
<Accordion multiple defaultValue={["storage", "seats"]}> <AccordionItem value="storage" title="Storage">50 GB per workspace, pooled across members.</AccordionItem> <AccordionItem value="seats" title="Seats">Up to 25 members; guests are free.</AccordionItem></Accordion>Controlled, with a heading level
Control the open items from state, and set headingLevel so the triggers fit the page outline.
const [open, setOpen] = useState<string[]>([]);<Accordion value={open} onValueChange={setOpen}> <AccordionItem value="vat" title="How do I add a VAT number?" headingLevel={2}> Go to Settings, Billing, Tax details and enter it with its country prefix. </AccordionItem></Accordion>API reference
Accordion
| Prop | Type | Default | Description |
|---|---|---|---|
value | string[] | Open items (controlled). | |
defaultValue | string[] | Initially open items (uncontrolled). | |
onValueChange | (value: string[]) => void | ||
multiple | boolean | false | Allow more than one item open at a time. |
disabled | boolean | Disables every item. | |
className | string | "" | Appended to the root's classes. |
Items are separated by hairlines. Only these props reach Base UI's Accordion.Root.
AccordionItem
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | Identifies the item in value. | |
title | ReactNode | The trigger's label. | |
headingLevel | 2 | 3 | 4 | 5 | 6 | 3 | The heading element that wraps the trigger. |
disabled | boolean | ||
children | ReactNode | The panel's content. | |
className | string | "" | Appended to the item's classes. |
Keyboard
| Key | Action |
|---|---|
Tab | Moves through the triggers, and into the content of open panels. |
Enter / Space | Opens or closes the focused item. |
Accessibility
- Each trigger is a button inside a real heading (
h3by default), witharia-expandedandaria-controlswired by Base UI. - A closed panel is hidden once it has finished collapsing, so its content leaves the tab order and the accessibility tree; while it closes it is
inert. - A disabled trigger turns muted and shows a not-allowed cursor.
Motion
The panel's height springs open on the smooth spring, which has no overshoot, and the content fades in over 200ms, starting 120ms in so it lands just after the height. The chevron turns 180° on the same spring. Closing fades the content out in 100ms while the height springs shut, so it is quicker than opening. Content that grows while open (an image loading, a list filtering) springs to its new height. Changing your mind mid-flight continues from the current height. Reduced motion snaps the height, fades the content in 100ms, and turns the chevron without a transition.
Notes for AI
Use Accordion for optional detail that people open in place, one AccordionItem per question or section, with a unique value for each. Pass multiple only when opening several at once helps, and set headingLevel to fit the surrounding headings.
Do not animate the panel's height yourself or wrap the content in another collapsible: Auto Height already measures and springs it, and keeps closed panels out of the tab order. Put padding inside your content, not on the item.
Related components
- Animated Tabs: one view at a time, switched from a row of tabs.
- Animated Group-By List
- Custom Scrollbar (Scroll Area)