Accordion

A set of collapsible panels with headings.

Lumi UI is an open-source component library designed for building beautiful and accessible user interfaces with React.

Installation

pnpm dlx shadcn@latest add @lumi-ui/accordion

Basic Usage

Import the Accordion, AccordionItem, AccordionHeader, AccordionTrigger, and AccordionPanel components. Compose them to create a basic accordion.

Lumi UI is an open-source component library designed for building beautiful and accessible user interfaces with React.

Variants

Underline (default)

Lumi UI is an open-source component library designed for building beautiful and accessible user interfaces with React.

Contained

You can install Lumi UI components via the CLI or by copying and pasting the component code directly into your project.

Outline

Recipes

Default Open Panels

To have an accordion item open by default, assign a unique value to the AccordionItem and pass that value in an array to the defaultValue prop on Accordion component.

Lorem ipsum dolor sit, amet consectetur adipisicing elit. Ipsam, consectetur.

To have multiple items open by default, ensure the multiple prop is set to true (which it is by default) and include each item's value in the defaultValue array.

Lorem ipsum dolor sit amet consectetur adipisicing elit. Ab, possimus.

Lorem ipsum dolor sit amet consectetur adipisicing elit. Ab, possimus.

Allowing a Single Open Panel

By default, users can open multiple panels at once. To restrict this so that only one panel can be open at a time, set the multiple prop to false.

Lumi UI enhances upon shadcn/ui by offering a more consistent API, additional component variants, and new features, while maintaining the same core principles.

Disable Panel

Pass disabled props to AccordionItem to disable a panel.

Anatomy

 <Accordion>
  <AccordionItem>
    <AccordionHeader>
      <AccordionTrigger/>
    </AccordionHeader>
    <AccordionPanel/>
  </AccordionItem>
 </Accordion>
ComponentRole
AccordionThe root component that provides context and controls the accordion's behavior and variants.
AccordionItemA wrapper for each individual collapsible section, uniquely identified by a value prop.
AccordionHeaderA required wrapper for the AccordionTrigger that renders as the h3.
AccordionTriggerThe button element that the user clicks to toggle the collapsed state of an AccordionPanel.
AccordionPanelThe component that wraps the content to be shown or hidden.

Migration from shadcn/ui

Component Naming & Structure

The Accordion component has been updated for better structural clarity and a more intuitive API for controlling behavior.

shadcn/uilumi/uiChange
AccordionTriggerAccordionHeader > AccordionTriggerAccordionTrigger is now explicitly wrapped by AccordionHeader.
AccordionContentAccordionPanelRenamed

Key Differences & New Features

Featurelumi/uishadcn/ui
Behavior Controlmultiple prop (defaults to true)type prop ("single" or "multiple")
Styling Variantsvariant prop (underline, contained, outline)customized with className
StructureRequires explicit <AccordionHeader> wrapper<AccordionTrigger> implicitly contains a header

Migration Example

demo-accordion.tsx
import {
  Accordion,
  AccordionContent,
  AccordionItem,
  AccordionTrigger,
} from "@/components/ui/accordion"
 
function Demo() {
  return (
    <Accordion type="single" collapsible>
      <AccordionItem value="item-1">
        <AccordionTrigger>Is it accessible?</AccordionTrigger>
        <AccordionContent>
          Yes. It adheres to the WAI-ARIA design pattern.
        </AccordionContent>
      </AccordionItem>
    </Accordion>
  );
}