Accordion

A stack of headings that each open and close a section of content.

Drafts save to your workspace every few seconds. A deleted draft stays in the trash for 30 days before it is removed.

import * as stylex from "@stylexjs/stylex"
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "@/components/ui/accordion"
import { width } from "@/theme/tokens.stylex"

const styles = stylex.create({
  accordion: { maxWidth: width.lg },
})

export default function AccordionDemo() {
  return (
    <Accordion defaultValue={["drafts"]} xstyle={styles.accordion}>
      <AccordionItem value="drafts">
        <AccordionTrigger>Where are my drafts saved?</AccordionTrigger>
        <AccordionContent>
          Drafts save to your workspace every few seconds. A deleted draft stays in the trash for 30
          days before it is removed.
        </AccordionContent>
      </AccordionItem>
      <AccordionItem value="sharing">
        <AccordionTrigger>Who can see a shared notebook?</AccordionTrigger>
        <AccordionContent>
          Only the people you invite. A link can be view-only or editable, and you can turn it off
          in the notebook&apos;s settings.
        </AccordionContent>
      </AccordionItem>
      <AccordionItem value="offline">
        <AccordionTrigger>Can I work without a connection?</AccordionTrigger>
        <AccordionContent>
          Yes. Edits you make offline stay on the device and sync the next time you connect.
        </AccordionContent>
      </AccordionItem>
    </Accordion>
  )
}

Installation

pnpm dlx shadcn@latest add @arene/accordion

Needs the arene setup first.

Usage

import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "@/components/ui/accordion"
<Accordion defaultValue={["item-1"]}>
  <AccordionItem value="item-1">
    <AccordionTrigger>Does it work with a keyboard?</AccordionTrigger>
    <AccordionContent>
      Yes. Tab moves between triggers, and Enter or Space opens one.
    </AccordionContent>
  </AccordionItem>
</Accordion>

value and defaultValue are arrays, one entry per open item, even when only one item can be open at a time.

Composition

Accordion
├── AccordionItem
│   ├── AccordionTrigger
│   └── AccordionContent
└── AccordionItem
    ├── AccordionTrigger
    └── AccordionContent

AccordionTrigger renders the Base UI Header and Trigger together, and AccordionContent renders the Panel around an inner element that holds the padding.

Multiple

Use the multiple prop to keep more than one item open at a time.

Choose when you hear about reviews that are due. Reminders arrive as a daily email digest or as a notification on your phone.

Decide who can open the workspace. Invite collaborators by email, require two-step sign-in and sign out devices you no longer use.

import * as stylex from "@stylexjs/stylex"
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "@/components/ui/accordion"
import { width } from "@/theme/tokens.stylex"

const styles = stylex.create({
  accordion: { maxWidth: width.lg },
})

const items = [
  {
    value: "reminders",
    trigger: "Reminders",
    content:
      "Choose when you hear about reviews that are due. Reminders arrive as a daily email digest or as a notification on your phone.",
  },
  {
    value: "access",
    trigger: "Sharing and access",
    content:
      "Decide who can open the workspace. Invite collaborators by email, require two-step sign-in and sign out devices you no longer use.",
  },
  {
    value: "plan",
    trigger: "Plan and invoices",
    content:
      "See which plan the workspace is on and download past invoices. Change the card on file or cancel the plan at any time.",
  },
]

export default function AccordionMultiple() {
  return (
    <Accordion multiple defaultValue={["reminders", "access"]} xstyle={styles.accordion}>
      {items.map((item) => (
        <AccordionItem key={item.value} value={item.value}>
          <AccordionTrigger>{item.trigger}</AccordionTrigger>
          <AccordionContent>{item.content}</AccordionContent>
        </AccordionItem>
      ))}
    </Accordion>
  )
}

Disabled

Use the disabled prop on AccordionItem to disable a single item, or on Accordion to disable all of them.

import * as stylex from "@stylexjs/stylex"
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "@/components/ui/accordion"
import { width } from "@/theme/tokens.stylex"

const styles = stylex.create({
  accordion: { maxWidth: width.lg },
})

export default function AccordionDisabled() {
  return (
    <Accordion xstyle={styles.accordion}>
      <AccordionItem value="members">
        <AccordionTrigger>How many people can join a workspace?</AccordionTrigger>
        <AccordionContent>
          Up to 50 on the standard plan. Owners add and remove members from the Members page in the
          workspace settings.
        </AccordionContent>
      </AccordionItem>
      <AccordionItem value="archive" disabled>
        <AccordionTrigger>Archived notebooks</AccordionTrigger>
        <AccordionContent>
          Archived notebooks are read-only. Restore the workspace to open this section.
        </AccordionContent>
      </AccordionItem>
      <AccordionItem value="email">
        <AccordionTrigger>How do I change my sign-in email?</AccordionTrigger>
        <AccordionContent>
          Change it under Account. We send a code to the new address, and the change applies once
          you enter it.
        </AccordionContent>
      </AccordionItem>
    </Accordion>
  )
}

Borders

Items draw a rule along their bottom edge, except the last. Add a frame through xstyle on the Accordion and inline padding on each AccordionItem.

Markdown, PDF and LaTeX. Exports keep equations, figures and citations, and a notebook with data can include its CSV files.

import * as stylex from "@stylexjs/stylex"
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "@/components/ui/accordion"
import { radius, space, width } from "@/theme/tokens.stylex"

const styles = stylex.create({
  accordion: {
    maxWidth: width.lg,
    borderWidth: 1,
    borderStyle: "solid",
    borderRadius: radius.xl,
  },
  item: { paddingInline: space.s4 },
})

const items = [
  {
    value: "exports",
    trigger: "Which formats can I export?",
    content:
      "Markdown, PDF and LaTeX. Exports keep equations, figures and citations, and a notebook with data can include its CSV files.",
  },
  {
    value: "versions",
    trigger: "Can I restore an earlier version?",
    content:
      "Yes. Every save is kept in the notebook's history. Open a version to compare it with the current one, then restore it.",
  },
  {
    value: "citations",
    trigger: "How do citations work?",
    content:
      "Paste a DOI or an arXiv ID and the reference fills itself in. The bibliography at the end of the notebook updates as you cite.",
  },
]

export default function AccordionBorders() {
  return (
    <Accordion defaultValue={["exports"]} xstyle={styles.accordion}>
      {items.map((item) => (
        <AccordionItem key={item.value} value={item.value} xstyle={styles.item}>
          <AccordionTrigger>{item.trigger}</AccordionTrigger>
          <AccordionContent>{item.content}</AccordionContent>
        </AccordionItem>
      ))}
    </Accordion>
  )
}

API reference

Pass render to replace a part's element or compose it with another component.

Every part wraps the Base UI Accordion part of the same name and accepts its props. See the Base UI reference for the full list. Each part also takes xstyle and className.

Accordion

PropTypeDefault
valuestring[]—
defaultValuestring[]—
onValueChange(value: string[], details) => void—
multiplebooleanfalse
disabledbooleanfalse
keepMountedbooleanfalse
hiddenUntilFoundbooleanfalse

hiddenUntilFound hides a closed panel with hidden="until-found" instead of unmounting it, which lets the browser's find-in-page reach the text and open the item. It overrides keepMounted.

AccordionItem

PropTypeDefault
valuestring—
disabledboolean—
onOpenChange(open: boolean, details) => void—

An item with no value gets a generated one. Set it when you control the accordion or want an item open on first render.

AccordionTrigger

PropTypeDefault
headerPropsAccordion.Header.Props—
styleCSSProperties—

The heading is the primitive's <h3>. Pass headerProps={{ render: <h2 /> }} to fit the page's outline.

style is real inline CSS, merged over the compiled styles.

AccordionContent

xstyle and className apply to the inner element. style takes real inline CSS on the panel. The panel animates its height between 0 and the measured content height, and a padded box of height 0 still draws its padding.

Data attributes

AttributeOnEffect
data-slot="accordion-content"the panelTargets the animated panel
data-starting-style, data-ending-stylethe panelBase UI writes them while the panel animates
data-open, data-disableditem, panelBase UI writes them
data-panel-open, data-disabledthe triggerBase UI writes them; the chevron flips
data-slot="accordion-trigger-icon"the chevronTargets the chevron from a parent

CSS variables

VariableOnEffect
--accordion-panel-heightthe panelBase UI writes the measured height; the panel transitions to it