Skip to content
opsinjs
Edit this page

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

Theme
Density
Text
Status
Accent theme
Accent
accordion · base base · style base-lyraOpen under the product theme

A frequently asked list

Three headers form an index; the reader opens one. Fictional copy.

Theme
Density
Text
Status
Accent theme
Accent
accordion-frequently-asked · base base · style base-lyraOpen under the product theme
accordion-frequently-asked.tsx
import { 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.

Theme
Density
Text
Status
Accent theme
Accent
accordion-one-open-at-a-time · base base · style base-lyraOpen under the product theme
accordion-one-open-at-a-time.tsx
import { 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 callout instead.
  • Content that must always be visible, not behind a header a reader has to press.Use card instead.
  • Choosing a header should swap the whole view for another in the same space, not reveal detail in place.Use tabs instead.

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.
KeyActionNotes
TabMoves focus to the next headerAn ordinary tab stop. A disabled header keeps its stop.
Shift+TabMoves focus to the previous headerThe same in reverse.
Enter, SpaceOpens or closes the focused sectionA native button. With multiple off, the open section closes.
Arrow keysNot boundBase UI follows the updated APG guidance, which dropped roving focus.
Contrast: 36 measured token pairs, 15 below floor
PairThemeAPCA LcWCAG 2.2Floor
body text on the pagelight101.617.18:1Pass
body text on the pagedark-100.518.00:1Pass
body text on a cardlight104.717.96:1Pass
body text on a carddark-99.616.32:1Pass
body text on the muted groundlight98.116.32:1Pass
body text on the muted grounddark-97.513.77:1Pass
secondary text on the pagelight83.97.42:1Pass
secondary text on the pagedark-80.713.44:1Pass
secondary text on a cardlight87.07.76:1Pass
secondary text on a carddark-79.812.19:1Pass
secondary text on the muted groundlight80.47.05:1Pass
secondary text on the muted grounddark-77.810.28:1Pass
a hairline boundary on the pagelight19.31.41:1Below floor
a hairline boundary on the pagedark-8.21.90:1Below floor
a hairline boundary on a cardlight22.41.47:1Below floor
a hairline boundary on a carddark-7.31.72:1Below floor
a hairline boundary on the muted groundlight15.81.34:1Below floor
a hairline boundary on the muted grounddark0.01.45:1Below floor
a placeholder boundary on the pagelight69.84.52:1Pass
a placeholder boundary on the pagedark-51.07.62:1Pass
a placeholder boundary on a cardlight72.84.72:1Pass
a placeholder boundary on a carddark-50.16.91:1Pass
a placeholder boundary on the muted groundlight66.24.29:1Pass
a placeholder boundary on the muted grounddark-48.15.83:1Pass
a placeholder fill on the pagelight8.31.18:1Below floor
a placeholder fill on the pagedark-8.21.90:1Below floor
a placeholder fill on a cardlight11.41.23:1Below floor
a placeholder fill on a carddark-7.31.72:1Below floor
a placeholder fill on the muted groundlight0.01.12:1Below floor
a placeholder fill on the muted grounddark0.01.45:1Below floor
a placeholder boundary on its own filllight58.93.84:1Pass
a placeholder boundary on its own filldark-41.54.01:1Below floor
the card hairline on the pagelight69.84.52:1Pass
the card hairline on the pagedark-28.74.19:1Below floor
the card hairline on a cardlight72.84.72:1Pass
the card hairline on a carddark-27.93.80:1Below 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

AttributeConditionValue
data-slotOn the root and each partaccordion, accordion-item, accordion-header, accordion-trigger, accordion-title, accordion-panel
data-openOn the item and the panelPresent while expanded
data-panel-openOn the triggerPresent while its section is open
data-disabledOn the item and its triggerPresent while disabled