Skip to content

Collapse

Pro

Content that opens and folds on its height, as an accordion when two switch together: reply fields, answers, more filters. Not an M3 component (@windmorph/react-pro).

import { Collapse } 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

Collapse 11 props

  • childrentype ReactNodeRequired

    What it shows while open.

  • opentype boolean

    Whether it's open (controlled). Folding keeps it mounted, showing what it last showed.

  • defaultOpentype booleandefault false

    Whether it starts open (uncontrolled).

  • keepMountedtype booleandefault false

    Keeps the content in the page while closed, as hidden="until-found": hidden and out of the accessibility tree and the Tab order, but find-in-page and #fragment links find it, and Collapse then opens at once (through onOpenChange), so the browser can scroll to the match. A page loaded with a #fragment inside it, or a hash changed to one, opens it and scrolls there too. The server's HTML has it too. Off, the content goes once it has folded.

  • appeartype booleandefault false

    Whether it opens with its motion when it mounts open (one added to the page already open). Otherwise it's simply there, as content present from the first render is, so the server's HTML never animates on hydration.

  • reftype Ref<HTMLDivElement>

    The root element. Its other props (id, className, style, aria-*, data-*) go to it too.

Events

  • onOpenChangetype ((open: boolean) => void)

    Called with the new state when Collapse opens itself: a keepMounted collapse opens when find-in-page or a #fragment link finds text inside it. Otherwise its control is the app's.

  • onClosedtype (() => void)

    After it has folded (and, unless keepMounted, its content is gone).

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.

  • A disclosure: a button that shows and hides content

    Built

    Use case · Disclosure

  • One open at a time, folding as the next opens

    Built

    Use case · Replies

  • Open from the start, with no opening motion (the default; appear opens it with motion)

    Built

    Configuration · Shown first

  • Kept in the page while closed, found by find-in-page (keepMounted)

    Built

    Configuration · Kept mounted

Theming & tokens

Set the timing with the tokens below, on the collapse or any ancestor. Style the parts with classNames (root, content).

Collapse tokens
VariableDefaultPaints
--wm-collapse-spring-durationvar(--md-sys-motion-spring-spatial-default-duration)How long opening and folding take (the default spatial spring).
--wm-collapse-spring-easingvar(--md-sys-motion-spring-spatial-default-easing)Opening's easing.
--wm-collapse-fold-easingvar(--md-sys-motion-spring-effects-default-easing)Folding's easing: the default effects spring, which never overshoots, so a folding height never bounces back open.
--wm-collapse-fade-durationvar(--md-sys-motion-spring-effects-default-duration)How long the content fades in and out (the default effects spring).
--wm-collapse-fade-easingvar(--md-sys-motion-spring-effects-default-easing)Its easing.