Caprice LogoCaprice UI

Accordion

A set of collapsible panels with headings.

Installation

npx shadcn@latest add @caprice/accordion

Usage

import * as Accordion from "@/components/caprice-ui/accordion"
<Accordion.Root>
  <Accordion.Item value="item-1">
    <Accordion.Trigger>What is Base UI?</Accordion.Trigger>
    <Accordion.Panel>
      Base UI is a library of high-quality unstyled React components for design systems
      and web apps.
    </Accordion.Panel>
  </Accordion.Item>
</Accordion.Root>

Examples

Single

Multiple

You can set up the accordion to allow multiple panels to be open at the same time using the multiple prop.

Controlled

Differences with shadcn/ui / Radix

If you're familiar with Radix UI and shadcn/ui, most patterns will carry over. This guide points out the differences so you can start using Caprice UI without surprises.

Key changes

Featureshadcn/uiCaprice UI
PrimitiveRadix AccordionBase UI Accordion
Multiple itemstype="multiple"multiple={true}
Single itemtype="single"Default (no prop needed)
Collapsiblecollapsible propAlways collapsible
Default valueString (single) or Array (multiple)Always Array
CompositionasChild proprender prop
Panel componentAccordionContentAccordionPanel (AccordionContent deprecated)
Open state attributedata-state="open"data-panel-open
AnimationCSS keyframe animationsCSS height transition via --accordion-panel-height
Hidden until foundNot supportedhiddenUntilFound={true}
Reduced motionNot includedmotion-reduce:transition-none
Disabled opacityopacity-50opacity-60

The hiddenUntilFound prop enables browser find-in-page (/Ctrl + F) to search content inside collapsed panels. When a match is found, the browser automatically expands the accordion item.

Comparison Example

shadcn/ui
<Accordion type="multiple" collapsible defaultValue="item-1">
  <AccordionItem value="item-1">
    <AccordionTrigger>Is it accessible?</AccordionTrigger>
    <AccordionContent>Yes. It adheres to the WAI-ARIA pattern.</AccordionContent>
  </AccordionItem>
</Accordion>
Caprice UI
<Accordion.Root multiple defaultValue={['item-1']}>
  <Accordion.Item value="item-1">
    <Accordion.Trigger>Is it accessible?</Accordion.Trigger>
    <Accordion.Panel>Yes. It adheres to the WAI-ARIA pattern.</Accordion.Panel>
  </Accordion.Item>
</Accordion.Root>

Accessibility

  • Keyboard navigation: Use / Arrow keys to move focus between accordion triggers, Home/End to jump to the first/last trigger, and Enter or Space to expand or collapse the focused panel.
  • ARIA attributes: The component automatically manages aria-expanded, aria-controls, and aria-labelledby to communicate state to assistive technologies. Each trigger is wrapped in a heading element for proper document structure.
  • Focus management: Focus remains on the trigger when expanding or collapsing panels, ensuring users don't lose their place in the document.
  • Hidden until found: Use the hiddenUntilFound prop on panels to enable browser find-in-page (/Ctrl + F) to search content inside collapsed panels. When a match is found, the browser automatically expands the accordion item.
  • Reduced motion: The component respects prefers-reduced-motion via motion-reduce:transition-none, disabling animations for users who prefer reduced motion.
  • Disabled items: Use the disabled prop on individual items to prevent interaction. Disabled triggers remain focusable so screen reader users can discover them and understand why they're unavailable.

API Reference