Accordion

Stacks sections that expand one at a time, or several at once.

import { Accordion } from "@usefragments/ui";Source

Preview

import { Accordion } from '@usefragments/ui';

<Accordion defaultValue={['item-1']}>
  <Accordion.Item value="item-1">
    <Accordion.Trigger>What is Fragments UI?</Accordion.Trigger>
    <Accordion.Content>

Usage

Use when

  • Answers most readers skip
  • Settings grouped by area
  • Long forms broken into stages
  • Navigation with nested children

Avoid when

  • Content everyone needs to read
  • A line or two — just show it
  • Steps in an order (use Stepper)
  • Switching between panels (use Tabs)

Implementation notes

  • Headers should say what is inside
  • Single mode when one answer at a time is enough
  • Multiple mode when sections get compared
  • Open the section most readers came for
  • Never nest an accordion inside an accordion

Installation

pnpm add @usefragments/ui

Import styles once from @usefragments/ui/styles. See the installation guide for framework and theme setup.

Anatomy

Import Accordion once, then compose its parts with dot notation.

  • Accordion.Item
  • Accordion.Trigger
  • Accordion.Content

Opening one section closes the last.

import { Accordion } from '@usefragments/ui';

<Accordion defaultValue={['item-1']}>
  <Accordion.Item value="item-1">
    <Accordion.Trigger>What is Fragments UI?</Accordion.Trigger>
    <Accordion.Content>
      Fragments UI is a modern React component library built on Base UI primitives, providing accessible and customizable components.
    </Accordion.Content>
  </Accordion.Item>
  <Accordion.Item value="item-2">
    <Accordion.Trigger>How do I install it?</Accordion.Trigger>
    <Accordion.Content>
      Install via npm or pnpm: pnpm add @usefragments/ui
    </Accordion.Content>
  </Accordion.Item>
  <Accordion.Item value="item-3">
    <Accordion.Trigger>Is it accessible?</Accordion.Trigger>
    <Accordion.Content>

Examples

Multiple Open

Sections stay open so answers can be compared.

import { Accordion } from '@usefragments/ui';

<Accordion multiple defaultValue={['features', 'pricing']}>
  <Accordion.Item value="features">
    <Accordion.Trigger>Features</Accordion.Trigger>
    <Accordion.Content>

With Disabled

An unavailable section stays visible but inert.

import { Accordion } from '@usefragments/ui';

<Accordion defaultValue={['available']}>
  <Accordion.Item value="available">
    <Accordion.Trigger>Notification preferences</Accordion.Trigger>
    <Accordion.Content>

API reference

Component props
Prop
Type
Default
Description
childrenRequiredReact.ReactNodeNot setAccordion items (use Accordion.Item with Accordion.Trigger and Accordion.Content)
classNamestring | undefinedNot set—
Content.childrenRequiredReact.ReactNodeNot set—
Content.classNamestring | undefinedNot set—
Content.hiddenUntilFoundboolean | undefinedNot setLet the browser's find-in-page reveal closed content.
Content.keepMountedboolean | undefinedNot setKeep the content mounted while closed.
defaultValueAccordionValue | undefinedNot setItems open at first (uncontrolled)
disabledboolean | undefinedfalseMake every item inert
headingLevelAccordionHeadingLevel | undefined3Semantic heading level for accordion triggers
Item.childrenRequiredReact.ReactNodeNot set—
Item.classNamestring | undefinedNot set—
Item.disabledboolean | undefinedNot setMake this item inert (focusable, dimmed once).
Item.valueRequiredstringNot setUnique value for this item.
multipleboolean | undefinedfalseLet several items stay open at once; a single accordion closes the open item when another opens or when it is pressed again
onValueChange((value: AccordionValue, eventDetails: AccordionChangeEventDetails) => void) | undefinedNot setCalled with the open items - (value: string[], eventDetails) => void
Trigger.childrenRequiredReact.ReactNodeNot set—
Trigger.classNamestring | undefinedNot set—
valueAccordionValue | undefinedNot setControlled open items

Accessibility

  • Keyboard navigation with Enter/Space to toggle
  • Uses proper ARIA expanded/controls attributes
  • Focus is visible on accordion triggers
  • TabsalternativeUse Tabs for horizontal switching between related views
  • DialogalternativeUse Dialog for focused content that interrupts the flow
  • CardcomplementaryAccordion items can contain Card-like content

Next steps