PeakUI

Accordion

Vertically stacked expandable sections

Usage

import {Accordion} from "@peakui/react";

Anatomy

import {Accordion} from "@peakui/react";

export default () => (
  <Accordion>
    <Accordion.Item>
      <Accordion.Heading>
        <Accordion.Trigger>
          <Accordion.Indicator />
        </Accordion.Trigger>
      </Accordion.Heading>
      <Accordion.Panel>
        <Accordion.Body />
      </Accordion.Panel>
    </Accordion.Item>
  </Accordion>
);

Examples

Multiple Expanded

Surface

Without Separator

Default Expanded

Controlled

Disabled

Customization

Tailwind CSS

<Accordion.Trigger className="px-2 py-3 text-base">
  Title
  <Accordion.Indicator className="text-accent" />
</Accordion.Trigger>

Global CSS

@layer components {
  .accordion {
    --accordion-radius: 1rem;
  }

  .accordion__trigger {
    @apply font-semibold;
  }

  .accordion__body-inner {
    @apply text-foreground;
  }
}

Styling Reference

PeakUI follows the BEM methodology, so variants and states are plain class names you can target.

CSS Classes

The Accordion component uses these CSS classes (view source styles):

Base Classes

  • .accordion - Group container
  • .accordion__item - Item, draws the separator
  • .accordion__heading - Heading wrapper
  • .accordion__trigger - Trigger button
  • .accordion__indicator - Chevron indicator
  • .accordion__panel - Collapsible panel with the height animation
  • .accordion__body - Body wrapper
  • .accordion__body-inner - Inner wrapper receiving the consumer className

Variant Classes

  • .accordion--surface - Filled, rounded container

Slots

  • [data-slot="accordion"] - The group element
  • [data-slot="accordion-item"] - An item
  • [data-slot="accordion-heading"] - The heading
  • [data-slot="accordion-trigger"] - The trigger button
  • [data-slot="accordion-indicator"] - The chevron indicator
  • [data-slot="accordion-panel"] - The collapsible panel
  • [data-slot="accordion-body"] - The body wrapper
  • [data-slot="accordion-body-inner"] - The inner body wrapper

CSS Variables

  • --accordion-radius - Corner radius of the surface variant. Defaults to min(32px, var(--radius-3xl))

Interactive States

  • Expanded: [data-expanded="true"] on the panel and the indicator; [aria-expanded="true"] on the trigger
  • Hover: :hover on the trigger, pointer devices only
  • Focus: :focus-visible or [data-focus-visible="true"] on the trigger
  • Disabled: :disabled or [aria-disabled="true"] on the trigger
  • No separator: [data-hide-separator="true"] on the item

API Reference

Accordion

PropTypeDefaultDescription
variant'default' | 'surface''default'Visual variant
hideSeparatorbooleanfalseHides the line between items
allowsMultipleExpandedbooleanfalseLets several items stay open
expandedKeysIterable<Key>-Controlled set of open item ids
defaultExpandedKeysIterable<Key>-Item ids open on first render
onExpandedChange(keys: Set<Key>) => any-Called when the open items change
isDisabledbooleanfalseDisables every item
childrenReactNode | ((values: DisclosureGroupRenderProps) => ReactNode)-Items, or a function of the render props
classNamestring | ((values: DisclosureGroupRenderProps) => string)-Additional classes, or a function of the render props
...restDisclosureGroupProps-Every other React Aria DisclosureGroup attribute

Accordion.Item

PropTypeDefaultDescription
idKey-Item id, matched against expandedKeys
isDisabledbooleanfalseDisables this item
childrenReactNode | ((values: DisclosureRenderProps) => ReactNode)-Heading and panel, or a function of the render props
classNamestring | ((values: DisclosureRenderProps) => string)-Additional classes, or a function of the render props
...restDisclosureProps-Every other React Aria Disclosure attribute

Accordion.Heading

PropTypeDefaultDescription
levelnumber3The heading level
classNamestring-Additional classes
...restHeadingProps-Every other attribute of a heading

Accordion.Trigger

PropTypeDefaultDescription
childrenReactNode | ((values: ButtonRenderProps) => ReactNode)-Trigger content, or a function of the render props
classNamestring | ((values: ButtonRenderProps) => string)-Additional classes, or a function of the render props
...restButtonProps-Every other React Aria Button attribute

Accordion.Indicator

PropTypeDefaultDescription
childrenReactNode-Replaces the built-in chevron <svg>
classNamestring-Additional classes
...restSVGProps-Every other attribute of an <svg>

Accordion.Panel

PropTypeDefaultDescription
childrenReactNode-Content to show and hide
classNamestring | ((values: DisclosurePanelRenderProps) => string)-Additional classes, or a function of the render props
...restDisclosurePanelProps-Every other React Aria DisclosurePanel attribute

Accordion.Body

PropTypeDefaultDescription
childrenReactNode-The body content
classNamestring-Additional classes, applied to the inner wrapper
renderDOMRenderFunction<'div', undefined>-Replaces the rendered <div> with your own
...restHTMLAttributes<HTMLDivElement>-Every other attribute of a <div>

Render Props

PropTypeDescription
children(values: DisclosureGroupRenderProps) => ReactNodeReceives expandedKeys, isDisabled
className(values: DisclosureGroupRenderProps) => stringSame values as children

On this page