Skip to content

Accordion

Pro

A stack of headers that open and fold panels of content, one at a time or several: FAQs, settings groups, product details and filters. Not an M3 component (@windmorph/react-pro).

import { Accordion, AccordionItem, AccordionHeader, AccordionPanel } from '@windmorph/react-pro';

Part of Windmorph Pro, paid components on the free core, not on sale yet. See the Pro guide for what it includes and to register interest.

Props

By name or description, across the 43 props below

Accordion 13 props

  • childrentype ReactNodeRequired

    The items: AccordionItems.

  • varianttype "standard" | "segmented"default "standard"

    standard: transparent rows with a divider between them, like a standard list. segmented: each item a container, 2px apart, with a segmented list's corners; the open item rounds fully.

  • multipletype booleandefault false

    Whether several items may be open at once (as <select multiple>). Otherwise opening one folds the others.

  • expandedKeystype Iterable<Key>

    The open items' ids (controlled).

  • defaultExpandedKeystype Iterable<Key>

    The items open at first (uncontrolled).

  • disabledtype booleandefault false

    Disables every item: headers can't be pressed or focused.

  • headingLeveltype 2 | 3 | 4 | 5 | 6default 3

    The heading level of every header (h2–h6), to fit the page's outline. An item or a header can set its own.

  • densitytype 0 | -1 | -2 | -3

    The density, 0 to -3: each step takes 4px off the headers' heights (56 → 44px), as a core list's. Left out, it follows the nearest data-density (--md-sys-density).

  • reftype Ref<HTMLDivElement>

    The root element. Its other props (id, className, style, e.g. --wm-accordion-* tokens, aria-*, data-*, handlers) go to it too.

Events

  • onExpandedChangetype ((keys: Set<Key>) => void)

    Called with the open items' ids when an item opens or folds.

Also accepts the root element's HTML attributes (id, data-*, event handlers).

AccordionItem 16 props

  • childrentype ReactNodeRequired

    The panel's content.

  • titletype ReactNode

    The header's title, which names its button (and its panel's region).

  • idtype Key

    The item's key in its accordion's expandedKeys. Not written to the page. Left out, the item gets a generated one (fine when nothing refers to it).

  • disabledtype booleandefault false

    Disables the item: its header can't be pressed or focused (React Aria's default).

  • expandedtype boolean

    Whether it's open (controlled), for an item outside an accordion.

  • defaultExpandedtype booleandefault false

    Whether it starts open (uncontrolled), for an item outside an accordion.

  • headingLeveltype 2 | 3 | 4 | 5 | 6default the accordion's, else 3

    The heading level of its header (h2–h6).

  • varianttype "standard" | "segmented"default "standard"

    How it's drawn when it stands alone; inside an accordion, the accordion's.

  • reftype Ref<HTMLDivElement>

    The item element.

  • leadingtype ReactNode

    Leading content before the title: an icon (20px, as a list item's), an avatar or an image.

  • supportingTexttype ReactNode

    A line under the title.

  • expandIcontype ReactNode

    Replaces the chevron at the end of the header. It turns over as the panel opens.

Events

  • onExpandedChangetype ((expanded: boolean) => void)

    Called with the new state whenever a person opens or folds the item: its header pressed, its content found by find-in-page or a #fragment link, or, in a one-at-a-time accordion, folded because another item opened (as a <details name> group fires toggle on the one it closes). Not called when the app changes expanded or the accordion's expandedKeys itself.

AccordionHeader 9 props

  • childrentype ReactNodeRequired

    The title, which names the header's button (and its panel's region).

  • headingLeveltype 2 | 3 | 4 | 5 | 6default the item's

    The heading level (h2–h6).

  • reftype Ref<HTMLButtonElement>

    The header's <button>. The other props (id, for a link to the heading, className, style, aria-*, data-*) go to the heading element, the header's outermost.

  • leadingtype ReactNode

    Leading content before the title: an icon (20px, as a list item's), an avatar or an image.

  • supportingTexttype ReactNode

    A line under the title.

  • expandIcontype ReactNode

    Replaces the chevron at the end of the header. It turns over as the panel opens.

Also accepts the root element's HTML attributes (id, data-*, event handlers).

AccordionPanel 5 props

  • childrentype ReactNodeRequired

    What the panel shows while open.

  • reftype Ref<HTMLDivElement>

    The panel element (the part that opens and folds). Its other props (id, className, style, e.g. --wm-collapse-* tokens, aria-*, data-*) go to it too.

Also accepts the root element's HTML attributes (id, data-*, event handlers).

Spec status

Not part of Material Design 3: a Windmorph Pro component, built on M3's colour roles, type scale, shapes and motion. Its variants and configurations each link to a live example.

  • Standard rows with dividers (variant="standard")

    Built

    Variant · Faq

  • Segmented containers (variant="segmented")

    Built

    Variant · Segmented, Parts

  • One item open at a time, which can fold fully

    Built

    Configuration · Faq

  • Several open at once, controlled (multiple, expandedKeys)

    Built

    Configuration · Multiple

  • Leading icons and supporting text

    Built

    Configuration · Multiple, Dense

  • A header from parts (AccordionHeader, AccordionPanel), and a disabled item

    Built

    Configuration · Parts

  • Density, as a core list (density)

    Built

    Configuration · Dense

  • Closed panels found by find-in-page and #fragment links

    Built

    Use case · Find in page

  • A FAQ, or a long answer with links

    Built

    Use case · Faq, Long panel

Theming & tokens

Set the tokens below on the accordion or any ancestor. The headers are list items, so they also take the core list's --md-comp-list-list-item-* tokens (heights, colours, type), and the panels take Collapse's --wm-collapse-* timing. Style the parts with classNames (root, item, heading, header, leading, title, supportingText, chevron, panel, content), on the accordion for every item or on one item.

Accordion tokens
VariableDefaultPaints
--wm-accordion-segmented-gap2pxThe space between segmented items (a segmented list’s 2px).
--wm-accordion-divider-colorvar(--md-sys-color-outline-variant)The line between standard items.
--wm-accordion-cornervar(--md-sys-shape-corner-extra-small)A segmented item’s corners at rest (a list item’s).
--wm-accordion-outer-cornervar(--md-sys-shape-corner-large)The outer corners of the first and last segmented items, and the corners that meet an open item.
--wm-accordion-hover-cornervar(--md-sys-shape-corner-medium)A segmented item’s corners while its header is hovered.
--wm-accordion-open-cornervar(--md-sys-shape-corner-large)A segmented item’s corners while it is open, or its header is focused or pressed (a list item’s active shape).
--wm-accordion-morph-durationvar(--md-sys-motion-spring-spatial-fast-duration)How long the corners morph and the chevron turns (the fast spatial spring; at once under reduced motion).
--wm-accordion-morph-easingvar(--md-sys-motion-spring-spatial-fast-easing)Their easing.
--wm-accordion-chevron-colorvar(--md-sys-color-on-surface-variant)The chevron at the end of each header.
--wm-accordion-chevron-size24pxThe chevron’s size.
--wm-accordion-panel-padding-inline16pxThe space on each side of a panel’s content, lined up with the header’s.
--wm-accordion-panel-padding-top0pxThe space above a panel’s content.
--wm-accordion-panel-padding-bottom16pxThe space below a panel’s content.
--wm-accordion-panel-text-colorvar(--md-sys-color-on-surface)A panel’s text.