Components
Accordion
Sections that expand and collapse, one or several at a time, built on Base UI Accordion.
Usage
pnpm dlx shadcn@latest add @opsinjs/accordion
The @opsinjs namespace is declared in your components.json. Everything it installs is code you then own. There is no runtime package to keep in step.
import { Accordion } from "@/components/ui/accordion"<Accordion
items={[
{ value: "hours", title: "When can I reach the team?", content: "Weekday mornings." },
{ value: "records", title: "Where are my notes kept?", content: "On your device." },
]}
/>Examples
accordion · base base · style base-lyraOpen under the product themeA frequently asked list
Three headers form an index; the reader opens one. Fictional copy.
accordion-frequently-asked · base base · style base-lyraOpen under the product themeimport { Accordion } from "@/components/ui/accordion"
export default function AccordionFrequentlyAsked() {
return (
<Accordion
className="w-full max-w-md"
items={[
{
value: "sync",
title: "Does the example app work offline?",
content:
"This imagined app keeps your entries on the device and syncs them when a connection returns. This is placeholder copy for the pattern, not a real feature.",
},
{
value: "share",
title: "Who can see what I add?",
content:
"Only you, until you choose to share a summary. No real data is shown in this preview; the answer is sample text.",
},
{
value: "delete",
title: "How do I remove an entry?",
content:
"A delete action would sit beside each row on the list screen of the fictional app. This answer exists to fill the panel, nothing more.",
},
]}
/>
)
}One section open at a time
With multiple off (the default), opening one section closes the last.
accordion-one-open-at-a-time · base base · style base-lyraOpen under the product themeimport { Accordion } from "@/components/ui/accordion"
export default function AccordionOneOpenAtATime() {
return (
<Accordion
className="w-full max-w-md"
defaultValue={["daily"]}
items={[
{
value: "daily",
title: "Daily view",
content:
"Shows the entries from a single example day. Sample text stands in for what the imagined screen would render.",
},
{
value: "weekly",
title: "Weekly view",
content:
"Groups the same fictional entries by week. This copy is a placeholder for the disclosure pattern, not a described feature.",
},
{
value: "monthly",
title: "Monthly view",
content:
"Rolls the imagined weeks into months. Opening this section closes the one above it, which is the single-open behaviour on show.",
},
]}
/>
)
}When to use it
Use it when
- An index of related sections a reader scans first and opens one at a time, such as questions and answers.
- Detail a reader wants on demand but not on arrival, such as small print under a summary.
- Several independent groups of settings on one small screen, opened together with multiple.
Do not use it when
- A safety message, an urgent instruction or anything a reader must not miss. A collapsed panel may never be opened.Use
calloutinstead. - Content that must always be visible, not behind a header a reader has to press.Use
cardinstead. - Choosing a header should swap the whole view for another in the same space, not reveal detail in place.Use
tabsinstead.
Accessibility
Axe, target-size, focus-visible and 320px reflow checks were clean. Base UI
renders each header as an h3 with a button, wires aria-expanded and
aria-controls between trigger and panel, and hides the chevron with
aria-hidden, so a reader relies on aria-expanded, not the glyph. The
chevron's turn uses --opsin-duration-fast, collapsed under
prefers-reduced-motion, and a closed panel is unmounted, leaving the tab order.
The audit fixed one SC 2.4.7 defect: the trigger's focus ring was drawn outside
the trigger, where the root's overflow-hidden clipped it, and it now renders
inside, whole on every straight edge.
Residual items.
- A small notch of the focus ring is still clipped at the first and last sections' outer corners.
- Every contrast pair against the card surface is unmeasured, not known-failing.
- That no must-see content may sit in a closed panel stays a docs contract the wrapper cannot enforce.
| Key | Action | Notes |
|---|---|---|
| Tab | Moves focus to the next header | An ordinary tab stop. A disabled header keeps its stop. |
| Shift+Tab | Moves focus to the previous header | The same in reverse. |
| Enter, Space | Opens or closes the focused section | A native button. With multiple off, the open section closes. |
| Arrow keys | Not bound | Base UI follows the updated APG guidance, which dropped roving focus. |
Contrast: 36 measured token pairs, 15 below floor
| Pair | Theme | APCA Lc | WCAG 2.2 | Floor |
|---|---|---|---|---|
| body text on the page | light | 101.6 | 17.18:1 | Pass |
| body text on the page | dark | -100.5 | 18.00:1 | Pass |
| body text on a card | light | 104.7 | 17.96:1 | Pass |
| body text on a card | dark | -99.6 | 16.32:1 | Pass |
| body text on the muted ground | light | 98.1 | 16.32:1 | Pass |
| body text on the muted ground | dark | -97.5 | 13.77:1 | Pass |
| secondary text on the page | light | 83.9 | 7.42:1 | Pass |
| secondary text on the page | dark | -80.7 | 13.44:1 | Pass |
| secondary text on a card | light | 87.0 | 7.76:1 | Pass |
| secondary text on a card | dark | -79.8 | 12.19:1 | Pass |
| secondary text on the muted ground | light | 80.4 | 7.05:1 | Pass |
| secondary text on the muted ground | dark | -77.8 | 10.28:1 | Pass |
| a hairline boundary on the page | light | 19.3 | 1.41:1 | Below floor |
| a hairline boundary on the page | dark | -8.2 | 1.90:1 | Below floor |
| a hairline boundary on a card | light | 22.4 | 1.47:1 | Below floor |
| a hairline boundary on a card | dark | -7.3 | 1.72:1 | Below floor |
| a hairline boundary on the muted ground | light | 15.8 | 1.34:1 | Below floor |
| a hairline boundary on the muted ground | dark | 0.0 | 1.45:1 | Below floor |
| a placeholder boundary on the page | light | 69.8 | 4.52:1 | Pass |
| a placeholder boundary on the page | dark | -51.0 | 7.62:1 | Pass |
| a placeholder boundary on a card | light | 72.8 | 4.72:1 | Pass |
| a placeholder boundary on a card | dark | -50.1 | 6.91:1 | Pass |
| a placeholder boundary on the muted ground | light | 66.2 | 4.29:1 | Pass |
| a placeholder boundary on the muted ground | dark | -48.1 | 5.83:1 | Pass |
| a placeholder fill on the page | light | 8.3 | 1.18:1 | Below floor |
| a placeholder fill on the page | dark | -8.2 | 1.90:1 | Below floor |
| a placeholder fill on a card | light | 11.4 | 1.23:1 | Below floor |
| a placeholder fill on a card | dark | -7.3 | 1.72:1 | Below floor |
| a placeholder fill on the muted ground | light | 0.0 | 1.12:1 | Below floor |
| a placeholder fill on the muted ground | dark | 0.0 | 1.45:1 | Below floor |
| a placeholder boundary on its own fill | light | 58.9 | 3.84:1 | Pass |
| a placeholder boundary on its own fill | dark | -41.5 | 4.01:1 | Below floor |
| the card hairline on the page | light | 69.8 | 4.52:1 | Pass |
| the card hairline on the page | dark | -28.7 | 4.19:1 | Below floor |
| the card hairline on a card | light | 72.8 | 4.72:1 | Pass |
| the card hairline on a card | dark | -27.9 | 3.80:1 | Below floor |
These are the measured token pairs this component draws colour from, not a measurement of the component itself.
Props interface
Prop
Type
Generated from AccordionProps in registry/bases/base/accordion.tsx.
multiple defaults to false. value without onValueChange fixes the open
sections as given. An empty items array renders nothing and warns in
development, as does a duplicated value.
Data attributes
| Attribute | Condition | Value |
|---|---|---|
| data-slot | On the root and each part | accordion, accordion-item, accordion-header, accordion-trigger, accordion-title, accordion-panel |
| data-open | On the item and the panel | Present while expanded |
| data-panel-open | On the trigger | Present while its section is open |
| data-disabled | On the item and its trigger | Present while disabled |