Breaking: Collapse is rebuilt on native details/summary
@trackunit/react-components (from 8.0.0) rebuilds Collapse on the browser's native <details> and <summary> elements. The open and close animation is now CSS-only, and keyboard handling, find-in-page and screen-reader behaviour come from the browser. Find-in-page opens a closed section that contains the match.
This is a breaking change for code that depends on the old header markup, on onToggle, or on interactive controls inside headerAddon. A migration updates what it can and lists the rest for manual review.
Why this changed
The previous Collapse measured its content height in JavaScript and wired up role="button", aria-expanded and aria-controls by hand. A native <details> does all of that, so Collapse now uses it and the browser handles the behaviour.
When it affects you
Nothing changes until you bump @trackunit/react-components to 8.0.0 or later. At that version:
onTogglehas a new event type. It changed fromMouseEvent<HTMLDivElement>toSyntheticEvent<HTMLElement>. In uncontrolled mode it fires from the nativetoggleevent, after the click. It also fires for browser-initiated toggles, such as find-in-page andnamegroups.animate={false}only turns the animation off. Children stay mounted while the section is closed. Pass the newlazyprop to render children only while the section is open, asanimate={false}used to. Lazy children mount a moment after the click that opens the section, so a test that checks them right after the click has to wait for them, for example withfindBy….- The header is a native
<summary>. It no longer hasrole="button",aria-expandedoraria-controls. Tests that find the header by role or readaria-expandedshould use the-headerand-detailstest ids. headerAddonmust be non-interactive. Clicks on interactive elements inside it no longer toggle the section, andstopPropagation()in an addon no longer prevents the toggle. Move interactive controls into the content, for example a toolbar row at the top.
// before
<Collapse animate={false} label="Details" onToggle={(event: MouseEvent<HTMLDivElement>, expanded) => track(expanded)}>
<ExpensiveContent />
</Collapse>
// after
<Collapse animate={false} lazy label="Details" onToggle={(event: SyntheticEvent<HTMLElement>, expanded) => track(expanded)}>
<ExpensiveContent />
</Collapse>
Less likely to affect you, and not breaking changes in the semver sense:
- jest-dom's
toBeVisible()is now false for collapsed content. It used to pass in jsdom, which doesn't apply the olddisplay: noneclass. - The header is a tab stop.
- The
Collapsecontainer no longer clips overflowing content. The content wrapper still clips its own. - The internal DOM changed: the content
idsits on a grid item inside<details>.
What the migration does
The package includes the v8-0-0-collapse-native-details migration.
- retypes
onTogglehandlers fromMouseEvent<HTMLDivElement>toSyntheticEvent<HTMLElement> - adds
lazynext toanimate={false} - reports for manual review:
Collapseelements that get their props from a spread,headerAddons that contain interactive controls, and tests that query the oldrole="button"header
Run these two commands in the consuming repo after bumping the dependency:
npx nx g @trackunit/migrations:migrate
npx nx g @trackunit/migrations:run-migrations
The first 8.0.x releases registered this migration under the wrong version, so upgrading from 7.x to them skipped it. Upgrade straight to the latest 8.x release to get it. If you already upgraded to an earlier 8.0.x release, a later upgrade won't run it either: update your Collapse usages by hand using the list above.
For the complete update process, see Maintaining Your Application.