Collapse
ProContent 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
What it shows while open.
Whether it's open (controlled). Folding keeps it mounted, showing what it last showed.
Whether it starts open (uncontrolled).
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#fragmentlinks find it, and Collapse then opens at once (throughonOpenChange), so the browser can scroll to the match. A page loaded with a#fragmentinside 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.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.
The root element. Its other props (
id,className,style,aria-*,data-*) go to it too.
Events
Called with the new state when Collapse opens itself: a
keepMountedcollapse opens when find-in-page or a#fragmentlink finds text inside it. Otherwise its control is the app's.After it has folded (and, unless
keepMounted, its content is gone).
Classes for each part.
Classes for the root element, merged with the component's own (yours win).
Inline styles for the root element.
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.
| Item | Status | Details |
|---|---|---|
| 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 |
A disclosure: a button that shows and hides content
BuiltUse case · Disclosure
One open at a time, folding as the next opens
BuiltUse case · Replies
Open from the start, with no opening motion (the default;
Builtappearopens it with motion)Configuration · Shown first
Kept in the page while closed, found by find-in-page (
BuiltkeepMounted)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).
| Variable | Default | Paints |
|---|---|---|
--wm-collapse-spring-duration | var(--md-sys-motion-spring-spatial-default-duration) | How long opening and folding take (the default spatial spring). |
--wm-collapse-spring-easing | var(--md-sys-motion-spring-spatial-default-easing) | Opening's easing. |
--wm-collapse-fold-easing | var(--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-duration | var(--md-sys-motion-spring-effects-default-duration) | How long the content fades in and out (the default effects spring). |
--wm-collapse-fade-easing | var(--md-sys-motion-spring-effects-default-easing) | Its easing. |