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.
Purpose
Content that opens and folds on its height: a reply field under a comment, an answer under a question, more filters. Folding to an unknown height smoothly, staying in the page until the fold ends and keeping what it showed meanwhile are easy to get wrong. It is not an M3 component, so it comes from @windmorph/react-pro.
For a stack of headers that each open a panel (an FAQ, settings groups) use Accordion, which is built on it; for text cut to a few lines, Expandable text; for content over the page, a dialog or a sheet.
Behaviour
open(ordefaultOpen, uncontrolled) opens and folds it on its grid track, so no height is measured. It opens on the default spatial spring and folds over the same time on the default effects spring's easing, which never overshoots, so a folding height never bounces back open (--wm-collapse-spring-duration,-spring-easing,-fold-easing). Its content fades on the default effects spring (-fade-duration,-fade-easing).- Folding keeps it in the page, showing what it last showed even if the app has moved on, and
inertso focus can't land in it;onClosedruns when it has folded. - Folded, its content goes, unless
keepMounted: then it stays in the page ashidden="until-found", out of the accessibility tree and the Tab order, but in the server's HTML. Find-in-page and a#fragmentlink find text inside it, and it opens at once throughonOpenChange, so the browser can scroll to the match. Otherwise its control is the app's, andonOpenChangedoesn't run. - Mounted open, it's simply there, for content shown from the start (
appearis off by default);appearopens it with its motion as it mounts. - Two switching on the same render (one folding as the other opens) move together on the folding curve, as an accordion, so what's around them stays put. A list of them should set
overflow-anchor: none, or the browser keeps the focused one still and scrolls the page around it. For a ready-made one, use Accordion. - Spacing that should fold with the content goes inside it (a margin or padding), not in a gap around it.
- Under reduced motion the height no longer animates: an opening collapse appears at full height and fades in, and a folding one fades out where it is, over
--wm-collapse-fade-duration, then goes (onClosedruns when the fade ends). One that folds as another opens goes at once, so what's below shifts once.
When not to use
For a stack of headers that open panels use Accordion; for text cut to a few lines, Expandable text; for content over the page, a dialog or a sheet.
See also
- Expandable text: Text cut to a few lines with "See more", shown only when it is cut, that expands it in place: posts, comments, reviews and bios. Not an M3 component (@windmorph/react-pro).
- Message field: A rounded field for writing something to send (a comment, a reply, a chat message) that grows from a pill into a box, with a send button, tools that open into their own row on focus, a reply banner, attachments and suggestions while typing (people after @, tags after #, emoji after :); plus its trigger. Not an M3 component (@windmorph/react-pro).
- List: Rows with headline, overline, supporting text and leading or trailing content (icons, avatars, images, video thumbnails); items can be links, switches, checkboxes or radio buttons, and put in order by drag or a menu.