Repository navigation
feat(collapsible): a headless disclosure for a trigger the product renders - #12356
kentonquatman wants to merge 8 commits into
Conversation
…nders useCollapsible returns triggerProps and contentProps, so a product can make a whole list row the disclosure button and keep its content element empty while closed. The optional hasContentAnimation keeps the children, inert, through the content's own close animation, and contentHeightProperty receives the content's measured height for grow and shrink keyframes. Collapsible gains an opt-in hasLazyMount that mounts its children only while open. Defaults are unchanged.
…er and content props
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
PR Analysis Report🔎 Preview ·
|
| Component | Size | LoC | Visual · A11y · RTL |
|---|---|---|---|
| Collapsible | 29.1 kB (+100 B) · 4.5 kB CSS (0) | — | ✓ · ✓ · ✓ |
| lab/Comments | 372.4 kB (+73 B) · 2.5 kB CSS (0) | — | — · — · — |
| Banner · Storybook | 68.0 kB (+68 B) · 11.3 kB CSS (0) | 513 (+1) | ✓ · ✓ · — |
3 more components
| Component | Size | LoC | Visual · A11y · RTL |
|---|---|---|---|
| lab/CommentComposer | 175.1 kB (+66 B) · 1.9 kB CSS (0) | — | — · — · — |
| lab/CommentThread | 365.5 kB (+58 B) · 2.4 kB CSS (0) | — | — · — · — |
| CollapsibleGroup | 7.0 kB (0) · 3.3 kB CSS (0) | — | ✓ · ✓ · ✓ |
Package size:
- @astryxdesign/cli 5.33 MB packed (+783 B); no new dependencies
- @astryxdesign/core 7.64 MB packed (+7.5 kB); no new dependencies
API changes: core +9 · ~0 · −0
9 API changes (advisory)
| Package | Where | Signature | Usage | |
|---|---|---|---|---|
| + | core |
. · Components · component Collapsible |
prop hasLazyMount?: boolean = false |
<Collapsible hasLazyMount /> |
| + | core |
. · Hooks · hook useCollapsibleContentMotion |
hook useCollapsibleContentMotion: (collapsible: Pick<UseCollapsibleReturn, 'isOpen' | 'contentProps'>, options?: UseCollapsibleContentMotionOptions) => UseCollapsibleContentMotionReturn |
import {useCollapsibleContentMotion} from '@astryxdesign/core'; useCollapsibleContentMotion(…) |
| + | core |
. · Types · interface UseCollapsibleContentMotionOptions |
interface UseCollapsibleContentMotionOptions |
import type {UseCollapsibleContentMotionOptions} from '@astryxdesign/core' |
| + | core |
. · Types · interface UseCollapsibleContentMotionReturn |
interface UseCollapsibleContentMotionReturn |
import type {UseCollapsibleContentMotionReturn} from '@astryxdesign/core' |
| + | core |
. · Types · interface UseCollapsibleReturn |
contentProps: { id: string; hidden: boolean } |
import type {UseCollapsibleReturn} from '@astryxdesign/core'; const x: UseCollapsibleReturn = {contentProps: …} |
| + | core |
. · Types · interface UseCollapsibleReturn |
triggerProps: { type: 'button'; 'aria-expanded': boolean; 'aria-controls': string; onClick: () => void } |
import type {UseCollapsibleReturn} from '@astryxdesign/core'; const x: UseCollapsibleReturn = {triggerProps: …} |
| + | core |
./Collapsible · Also exported from an earlier entry point · UseCollapsibleContentMotionOptions |
UseCollapsibleContentMotionOptions (.) |
import {UseCollapsibleContentMotionOptions} from '@astryxdesign/core/Collapsible' |
| + | core |
./Collapsible · Also exported from an earlier entry point · UseCollapsibleContentMotionReturn |
UseCollapsibleContentMotionReturn (.) |
import {UseCollapsibleContentMotionReturn} from '@astryxdesign/core/Collapsible' |
| + | core |
./Collapsible · Also exported from an earlier entry point · useCollapsibleContentMotion |
useCollapsibleContentMotion (.) |
import {useCollapsibleContentMotion} from '@astryxdesign/core/Collapsible' |
Touched components checked; for the full suites, add ci:run-visual for Visual, ci:run-a11y for Accessibility, ci:run-rtl for RTL.
Generated by PR Enrichment workflow | View full report
…he hook useCollapsible generates the content id now. Collapsible and Banner reuse it instead of calling useId again, so each still takes one generated id from the page and every later id keeps the value it had.
There was a problem hiding this comment.
Changes requested: six fixes are needed, and the new API also waits on an engineering owner's decision.
Blocking
- The content-animation and height code ships with
useCollapsible, which Collapsible and Banner always import, so a page that renders Collapsible without the new options grows by 771 B gzip (634 B of it the unused optional code) against the 0.3 KB an unused optional feature may add; move it behind its own import or a deferred load, and report the per-page delta. - Miss:
reducesMotioninuseCollapsible.tsre-implements the shared Reduce Motion policy inmotion/reducedMotion.tsand drops its coarse-pointer cross-fade, so a touch row snaps under Reduce Motion; take the answer fromreducedMotionFade(node)instead. - Rows that change in one commit, such as a
CollapsibleGroupaccordion, each writeanimation-name, read the height and write again in turn, forcing an extra layout per row; read every changing row's height before any write. useCollapsible.tsis now 379 lines and about 4.5 KB gzip of behavior code that reuses no shared engine; build the phases onanimatedLayout, as Collapsible's own exit already does, or record in the Collapsible record why none fits.- With
hasContentAnimation, a close that drops the children at once (no running animation, or Reduce Motion) still measures and writes the height, while the description, JSDoc, docs and draft FR9 say only animated closes do; check the hold before measuring a close and test that case. - The description says existing callers keep their generated ids, but every direct
useCollapsiblecall now takes one id from the page; narrow it to Collapsible and Banner.
Owner decision: no current record decides the eight new API rows, the draft useCollapsible module record or Collapsible's proposed FR11, including how the touch cross-fade rule applies to caller-animated rows. An engineering owner records approval by commenting /approve-spec <full head SHA> on this pull request; the author may do so if they are an engineering owner. The earlier blocker about duplicated disclosure wiring is fixed.
Claims and files checked
Review mode: full; reason: author-not-engowner
Claims:
- CLI changeset, the template block wires its trigger and content with the hook's props so the trigger always names an element: verified (
CollapsibleHookUsage.tsx:23-38). - Core changeset, the hook returns trigger and content props and closed content mounts nothing: verified when children are gated on
isPresent(all 200 closed story rows empty in Chromium). - Core changeset,
hasContentAnimationkeeps children through the content's close animation: verified (content animation tests; Chromium close probe). - Core changeset,
contentHeightPropertyreceives the measured height: verified (content height tests; 76 px in Chromium). - Core changeset,
hasLazyMountmounts children only while open: verified (lazy suite; 2 of 20 mounted in the Lazy mount story). - Collapsible keeps closed children mounted and hidden today: verified (lazy suite default case).
- The old pattern leaves
aria-controlsnaming a missing element while closed: verified (base template block). - Phases last while the content's own animation plays, with the children inert until it ends or is cancelled: verified (tests; Chromium).
- With no running animation or under Reduce Motion the phase ends before the frame paints: verified (tests; Chromium touch probe).
- The height is measured once per open and animated close: false (also at closes that drop the children at once).
hasLazyMountkeeps the empty region, keeps children through an animated-layout close and keeps focus return: verified (lazy suite; animated-layout lazy exit test).- Collapsible and Banner each take one generated id from the page: verified (
Collapsible.test.tsxgenerated ids). - Existing callers keep their generated ids: false for direct hook callers (
useCollapsible.ts:283). - No theming target, token or data attribute changes: verified (generated API delta: 8 core rows, 0 theme rows).
- Without the options the hook writes nothing to the DOM: verified.
- The named test suites and typechecks pass: verified for the Collapsible, Banner, animated-layout and doc suites (715 tests), the core typecheck and the template-docs typecheck.
- Real-browser frames of the grow and fade were not shown: this review captured the open and close in Chromium.
Files:
.changeset/the-usecollapsible-template-block-wires-its-trig-v9i6.md: clear..changeset/usecollapsible-returns-triggerprops-and-contentp-10sw.md: clear.apps/storybook/stories/Collapsible.stories.tsx: clear.apps/storybook/stories/CollapsibleA11y.stories.tsx: clear.docs/specs/components/Collapsible/Collapsible.spec.md: owner decision (FR11, concept row, ownership lines).docs/specs/components/Collapsible/modules/useCollapsible.spec.md: owner decision; FR9 claim false; temporary status line 41 (non-blocking).packages/cli/assets/templates/blocks/components/Collapsible/CollapsibleHookUsage.tsx: clear.packages/core/src/Banner/Banner.tsx: clear.packages/core/src/Collapsible/Collapsible.doc.mjs: clear.packages/core/src/Collapsible/Collapsible.test.tsx: clear.packages/core/src/Collapsible/Collapsible.tsx: clear.packages/core/src/Collapsible/__tests__/Collapsible.a11y.states.ts: clear.packages/core/src/Collapsible/__tests__/useCollapsible.a11y.test.tsx: clear.packages/core/src/Collapsible/useCollapsible.doc.mjs: height claim false.packages/core/src/Collapsible/useCollapsible.test.tsx: clear; the height suite misses the animated-option close case.packages/core/src/Collapsible/useCollapsible.ts: first-load cost, duplicated Reduce Motion check, interleaved reads, engine rule, measurement order, ids claim.packages/core/src/motion/animatedLayoutAdopters.test.tsx: clear.
… that drops its children Content elements that change in one commit are measured together: every animation is suppressed, then every height is read, then every value is written, so accordion rows that open and close together force one layout. A close is measured only when its own animation holds the children. The record and the release note say that a direct useCollapsible call takes one generated id.
There was a problem hiding this comment.
Changes requested: three fixes are needed, and the new API also waits on an engineering owner's decision.
Blocking
- The content-animation and height code ships with
useCollapsible, which Collapsible and Banner always import, so a page that renders Collapsible without the new options carries 741 B gzip of unused optional code (871 B in all, by the description's own table) against the 0.3 KB an unused optional feature may add; move it behind its own import or a deferred load. - Miss:
reducesMotioninuseCollapsible.tsstill re-implements the shared Reduce Motion policy inmotion/reducedMotion.tsand drops its coarse-pointer cross-fade, so a touch row snaps open and shut under Reduce Motion; take the answer fromreducedMotionFade(node)instead. useCollapsible.tsis now 412 lines and about 5 KB gzip of behavior code that reuses no shared engine; build the phases onanimatedLayout, as Collapsible's own exit already does, or record in the Collapsible record why none fits.
Owner decision: no current record decides the eight new API rows, the draft useCollapsible module record or Collapsible's proposed FR11, including how the touch cross-fade rule applies to caller-animated rows. An engineering owner records approval by commenting /approve-spec <full head SHA> on this pull request; the author may do so if they are an engineering owner. The batched height pass, the skipped measurement for closes that drop their children, the narrowed id claim and the record's status line fix the earlier findings.
Claims and files checked
Review mode: full; reason: author-not-engowner
Claims:
- CLI changeset, the template block wires its trigger and content with the hook's props so the trigger names an element that stays in the page: verified (
CollapsibleHookUsage.tsx:23-38). - Core changeset, the hook returns trigger and content props and closed content mounts nothing: verified when children are gated on
isPresent(props tests; all 200 closed story rows empty in Chromium). - Core changeset,
hasContentAnimationkeeps the children through the content's close animation: verified (content animation tests; Chromium close probe). - Core changeset,
contentHeightPropertyreceives the measured height: verified (content height tests; 76 px in Chromium). - Core changeset,
hasLazyMountmounts children only while open: verified (lazy suite; 2 of 20 mounted in the Lazy mount story). - Core changeset, a direct hook call takes one generated id while Collapsible and Banner keep theirs: verified (
useCollapsible.ts:313,Collapsible.tsx:514,Banner.tsx:579; generated-ids test; the same ids base and head in Chromium). - Collapsible draws its own trigger and the base hook had no ids, ARIA wiring or presence: verified (base hook).
- The usual pattern leaves
aria-controlsnaming a missing element while closed: verified (base template block). - Collapsible keeps closed children mounted and hidden today: verified (lazy suite default case).
- Phases last while the content's own animation plays, with the children inert until it ends or is cancelled: verified (tests; Chromium).
- With no running animation or under Reduce Motion the phase ends before the frame paints: verified (tests; Chromium touch probe).
- The height is measured once per open and animated close, with the animation suppressed for the read: verified (content height tests, including the two new close cases).
- Rows that change in one commit are measured in one pass: verified (accordion test).
hasLazyMountkeeps the empty region, keeps children through an animated-layout close and keeps focus return: verified (lazy suite; animated-layout lazy exit test).- Existing Collapsible and Banner callers see no behavior change and keep their generated ids: verified (default frames pixel-identical; ids test).
- Without the options the hook writes nothing to the DOM: verified (
useCollapsible.ts:333-390). - No theming target, token or data attribute changes: verified (generated API delta: 8 core rows, 0 theme rows).
- First-load size table: verified for the head column (both component pages reproduced exactly; reference pages +0).
- The hook file is over the 300-line engine threshold: verified (412 lines).
- The close ends with
flushSyncfrom the content's ownanimationend: verified (useCollapsible.ts:351). - Build, Core typecheck, strict lint of the changed files and the targeted suites pass: verified (718 tests at this head; the stated 714 predates the latest commit's tests).
- Full UI project, CLI tests, repository checks and changeset coverage pass: not rerun.
- Real-browser frames of the grow and fade were not shown: Chromium probes of the open and close were taken for this review.
Files:
.changeset/the-usecollapsible-template-block-wires-its-trig-v9i6.md: clear..changeset/usecollapsible-returns-triggerprops-and-contentp-10sw.md: clear.apps/storybook/stories/Collapsible.stories.tsx: clear.apps/storybook/stories/CollapsibleA11y.stories.tsx: clear.docs/specs/components/Collapsible/Collapsible.spec.md: owner decision (FR11, concept row, ownership lines).docs/specs/components/Collapsible/modules/useCollapsible.spec.md: owner decision (draft FR1-FR9, PR1-PR2, FR8 against the touch cross-fade rule).packages/cli/assets/templates/blocks/components/Collapsible/CollapsibleHookUsage.tsx: clear.packages/core/src/Banner/Banner.tsx: clear.packages/core/src/Collapsible/Collapsible.doc.mjs: clear.packages/core/src/Collapsible/Collapsible.test.tsx: clear.packages/core/src/Collapsible/Collapsible.tsx: clear.packages/core/src/Collapsible/__tests__/Collapsible.a11y.states.ts: clear.packages/core/src/Collapsible/__tests__/useCollapsible.a11y.test.tsx: clear.packages/core/src/Collapsible/useCollapsible.doc.mjs: clear.packages/core/src/Collapsible/useCollapsible.test.tsx: clear.packages/core/src/Collapsible/useCollapsible.ts: first-load cost, duplicated Reduce Motion check, engine rule.packages/core/src/motion/animatedLayoutAdopters.test.tsx: clear.
…Core The map of content elements that wait for a height measurement lives under a registered shared key, so two copies of Core on one page share one pass.
There was a problem hiding this comment.
Changes requested: three fixes are needed, and the new API also waits on an engineering owner's decision.
Blocking
- The content-animation and height code ships with
useCollapsible, which Collapsible and Banner always import, so a page that renders Collapsible without the new options carries 758 B gzip of unused optional code (890 B in all against the merge base, more than the description's table, which predates the latest commit) against the 0.3 KB an unused optional feature may add; move it behind its own import or a deferred load and update the table. - Miss:
reducesMotioninuseCollapsible.tsstill re-implements the shared Reduce Motion policy inmotion/reducedMotion.tsand drops its coarse-pointer cross-fade, so a touch row snaps open and shut under Reduce Motion; take the answer fromreducedMotionFade(node)instead. useCollapsible.tsis now 419 lines and about 5 KB gzip of behavior code that reuses no shared engine; build the phases onanimatedLayout, as Collapsible's own exit already does, or record in the Collapsible record why none fits.
Owner decision: no current record decides the eight new API rows, the draft useCollapsible module record or Collapsible's proposed FR11, including how the touch cross-fade rule applies to caller-animated rows. An engineering owner records approval by commenting /approve-spec <full head SHA> on this pull request; the author may do so if they are an engineering owner. The shared height queue in the latest commit is fine as written.
Claims and files checked
Review mode: full; reason: author-not-engowner
Claims:
- CLI changeset, the template block wires its trigger and content with the hook's props so the trigger names an element that stays in the page: verified (
CollapsibleHookUsage.tsx:24-35). - Core changeset, the hook returns trigger and content props and closed content mounts nothing: verified when children are gated on
isPresent(props tests; all 200 closed story rows empty in Chromium). - Core changeset,
hasContentAnimationkeeps the children through the content's close animation: verified (content animation tests; Chromium close probe). - Core changeset,
contentHeightPropertyreceives the measured height: verified (content height tests; 76 px in Chromium). - Core changeset,
hasLazyMountmounts children only while open: verified (lazy suite; 2 of 20 mounted in the Lazy mount story). - Core changeset, a direct hook call takes one generated id while Collapsible and Banner keep theirs: verified (
useCollapsible.ts:320,Collapsible.tsx:514,Banner.tsx:579; generated-ids test; the same ids base and head in Chromium). - Collapsible draws its own trigger and the base hook had no ids, ARIA wiring or presence: verified (base hook).
- The usual pattern leaves
aria-controlsnaming a missing element while closed: verified (base template block). - Collapsible keeps closed children mounted and hidden today: verified (lazy suite default case).
- Phases last while the content's own animation plays, with the children inert until it ends or is cancelled: verified (tests; Chromium).
- With no running animation or under Reduce Motion the phase ends before the frame paints: verified (tests; Chromium touch probe).
- The height is measured once per open and animated close, with the animation suppressed for the read: verified (content height tests).
- Rows that change in one commit are measured in one pass, shared by every copy of Core: verified (accordion test;
useCollapsible.ts:205-232). hasLazyMountkeeps the empty region, keeps children through an animated-layout close and keeps focus return: verified (lazy suite; animated-layout lazy exit test).- Existing Collapsible and Banner callers see no behavior change and keep their generated ids: verified (default frames pixel-identical; ids test).
- Without the options the hook writes nothing to the DOM: verified (
useCollapsible.ts:340-397). - No theming target, token or data attribute changes: verified (generated API delta: 8 core rows, 0 theme rows).
- First-load size table: false at this head; the base column is reproduced exactly, but the head now measures 78,101 / 26,714 and 194,657 / 65,393 bytes (+890 B and +851 B gzip), with the reference pages +0.
- The hook file is over the 300-line engine threshold: verified (419 lines).
- The close ends with
flushSyncfrom the content's ownanimationend: verified (useCollapsible.ts:358). - Build, Core typecheck, the CLI template typecheck, strict lint of the changed files and the targeted suites pass: verified (724 tests including the shared-state suite; the stated 714 predates later tests).
- Full UI project, CLI tests, repository checks and changeset coverage pass: not rerun.
- Real-browser frames of the grow and fade were not shown: Chromium probes of the open and the close stand in for them.
Files:
.changeset/the-usecollapsible-template-block-wires-its-trig-v9i6.md: clear..changeset/usecollapsible-returns-triggerprops-and-contentp-10sw.md: clear.apps/storybook/stories/Collapsible.stories.tsx: clear.apps/storybook/stories/CollapsibleA11y.stories.tsx: clear.docs/specs/components/Collapsible/Collapsible.spec.md: owner decision (FR11, concept row, ownership lines).docs/specs/components/Collapsible/modules/useCollapsible.spec.md: owner decision (draft FR1-FR9, PR1-PR2, FR8 against the touch cross-fade rule).packages/cli/assets/templates/blocks/components/Collapsible/CollapsibleHookUsage.tsx: clear.packages/core/src/Banner/Banner.tsx: clear.packages/core/src/Collapsible/Collapsible.doc.mjs: clear.packages/core/src/Collapsible/Collapsible.test.tsx: clear.packages/core/src/Collapsible/Collapsible.tsx: clear.packages/core/src/Collapsible/__tests__/Collapsible.a11y.states.ts: clear.packages/core/src/Collapsible/__tests__/useCollapsible.a11y.test.tsx: clear.packages/core/src/Collapsible/useCollapsible.doc.mjs: clear.packages/core/src/Collapsible/useCollapsible.test.tsx: clear.packages/core/src/Collapsible/useCollapsible.ts: first-load cost, duplicated Reduce Motion check, engine rule.packages/core/src/motion/animatedLayoutAdopters.test.tsx: clear.
useCollapsible keeps the headless basics: triggerProps, contentProps (id and hidden), and content that mounts nothing while closed. The motion phases, presence through the close, and the measured height property move to useCollapsibleContentMotion, a separate import that useCollapsible, Collapsible, and Banner never load. Against the merge base, a Collapsible page now grows 109 B gzip and a Banner page 56 B. Under Reduce Motion the new hook follows the shared policy: a fine pointer opens and closes at once, and a coarse pointer waits for the content's cross-fade. A new template block shows the hook, and two draft module records describe the two hooks.
|
The three blocking findings from the review on 9704243, and their fixes in aa0f95b:
The owner decision on the API rows and the two draft module records stays open. |
There was a problem hiding this comment.
Waiting on an engineering owner's API decision; no blocking code issue remains at this head, and the three fixes from the last review are in.
Owner decision needed: no current record decides the new public API (useCollapsible's triggerProps and contentProps, the new useCollapsibleContentMotion hook with its options and return, and Collapsible's hasLazyMount), the two draft module records, Collapsible's proposed FR11, or the extra generated id that a direct useCollapsible call now takes. The same decision can settle how the motion record's Reduce Motion rule (FR7) treats a theme that reduces motion for everyone, since caller CSS can only see the prefers-reduced-motion query. An engineering owner records it by commenting /approve-spec <full head SHA> on this pull request; the author may do so if they are an engineering owner.
Non-blocking:
- The
useCollapsibleContentMotiondoc listsheightPropertyas a second parameter; name itoptions.heightProperty, as theuseAnimatedLayoutanduseCalendarConstraintsdocs do, so the CLI shows the real signature. measureNaturalHeightonly queues the element andflushNaturalHeightsmeasures it;queueNaturalHeightwould say what it does.
Claims and files checked
Review mode: full; reason: author-not-engowner
Claims:
- CLI release note, the hook's template block spreads the trigger and content props so the trigger names an element that stays while closed: verified (
CollapsibleHookUsage.tsx:23-38). - CLI release note, a new animated-details block grows and fades to the measured height and shrinks and fades out: verified (
CollapsibleContentMotionUsage.tsx:20-29,:77-108). - Core release note, the hook returns trigger and content props and closed content mounts nothing: verified when children are gated on
isOpen(props tests; 200 closed story rows empty in Chromium). - Core release note, the motion hook is a separate import that keeps the children through the close animation and writes the measured height: verified (motion tests; Chromium close probe; 76 px).
- Core release note, under Reduce Motion a touch screen cross-fades and other pointers change at once: verified for the system setting (Reduce Motion tests; Chromium on a Pixel 7 profile and a desktop pointer).
- Core release note,
hasLazyMountmounts children only while open: verified (lazy suite; 2 of 20 mounted in the story). - Core release note, a direct hook call takes one generated id while Collapsible and Banner keep theirs: verified (
useCollapsible.ts:163,Collapsible.tsx:514,Banner.tsx:579; one-id test). - Collapsible draws its own trigger, and the base hook had no ids, wiring or presence: verified (base hook).
- The usual pattern leaves
aria-controlsnaming a missing element while closed: verified (base template block). - Collapsible keeps closed children mounted and hidden today: verified (lazy suite default case).
- Phases last while the content's own animation plays, the children stay inert until it ends or is cancelled, and with no running animation the phase ends before paint: verified (motion tests; Chromium).
- Reduce Motion takes its answer from the shared policy: verified (
useCollapsibleContentMotion.ts:77-79; four Reduce Motion tests). - The height is read once per open and animated close, with the animation suppressed, in one pass per commit: verified (height tests, including the two-row accordion case).
useCollapsible, Collapsible and Banner import none of the motion code: verified (their imports at this head).- First-load size table, +109 B and +56 B gzip with the reference pages unchanged: verified, reproduced exactly.
useCollapsible.tsis 180 lines and the motion module 244 lines and 2,984 B gzip: verified.hasLazyMountkeeps the empty region, keeps children through an animated close and keeps focus return: verified (lazy suite; animated-layout lazy exit test).- No behavior change for existing Collapsible and Banner callers, whose ids keep their values: verified (default case and one-id test; both files unchanged since their last pixel-identical frames).
- The hook writes nothing to the DOM, and no theming target, token or data attribute changes: verified (hook source; the generated API delta has core rows only).
- The close ends with
flushSyncfrom the content's ownanimationend: verified (useCollapsibleContentMotion.ts:194). - Test counts of 20 and 22 in the two hook suites: verified.
- Each new test fails against the code it guards: not rerun.
- Build, typechecks, targeted suites, lint and the size script pass: verified for the Core and CLI template typechecks, 589 targeted tests, strict lint of the changed files and the size script; the full UI and node projects were not rerun.
- Real-browser frames of the grow and fade are not shown: Chromium probes at this head show the hold and the release.
Files:
.changeset/the-usecollapsible-template-block-wires-its-trig-v9i6.md: clear..changeset/usecollapsible-returns-triggerprops-and-contentp-10sw.md: clear.apps/sandbox/scripts/next-export-routes.json: clear (generated).apps/storybook/stories/Collapsible.stories.tsx: clear.apps/storybook/stories/CollapsibleA11y.stories.tsx: clear.docs/specs/components/Collapsible/Collapsible.spec.md: owner decision (FR11, concept row, ownership lines).docs/specs/components/Collapsible/modules/useCollapsible.spec.md: owner decision (draft requirements and open questions).docs/specs/components/Collapsible/modules/useCollapsibleContentMotion.spec.md: owner decision (draft requirements, FR7's theme case).internal/shadcn-registry/routes.lock.json: clear (generated).packages/cli/assets/templates/blocks/components/Collapsible/CollapsibleContentMotionUsage.doc.mjs: clear.packages/cli/assets/templates/blocks/components/Collapsible/CollapsibleContentMotionUsage.tsx: clear.packages/cli/assets/templates/blocks/components/Collapsible/CollapsibleHookUsage.tsx: clear.packages/cli/test/__golden__/no-icon-set/search-close.json: clear (golden).packages/cli/test/__golden__/no-icon-set/search-close.txt: clear (golden).packages/core/src/Banner/Banner.tsx: clear.packages/core/src/Collapsible/Collapsible.doc.mjs: clear.packages/core/src/Collapsible/Collapsible.test.tsx: clear.packages/core/src/Collapsible/Collapsible.tsx: clear.packages/core/src/Collapsible/__tests__/Collapsible.a11y.states.ts: clear.packages/core/src/Collapsible/__tests__/useCollapsible.a11y.test.tsx: clear.packages/core/src/Collapsible/index.ts: clear.packages/core/src/Collapsible/useCollapsible.doc.mjs: clear.packages/core/src/Collapsible/useCollapsible.test.tsx: clear.packages/core/src/Collapsible/useCollapsible.ts: clear.packages/core/src/Collapsible/useCollapsibleContentMotion.doc.mjs: non-blocking (parameter name).packages/core/src/Collapsible/useCollapsibleContentMotion.test.tsx: clear.packages/core/src/Collapsible/useCollapsibleContentMotion.ts: non-blocking (helper name).packages/core/src/motion/animatedLayoutAdopters.test.tsx: clear.
|
|
||
| /** Whether the running animation holds the phase, under the Reduce Motion policy. */ | ||
| function holdsMotion(node: HTMLElement): boolean { | ||
| return reducedMotionFade(node)?.duration !== 0 && isAnimating(node); |
There was a problem hiding this comment.
Non-blocking, for the owner deciding FR7: reducedMotionFade also counts a theme that reduces motion for everyone, but caller CSS can key only on prefers-reduced-motion, as the template block and story do. Once a theme can resolve reducedMotion: 'always', a touch row in it would hold its phase for the full grow and shrink. Ending the phase at once when only the theme reduces motion would keep the two in step.
…function The useCollapsibleContentMotion doc lists `options` and `options.heightProperty`, so the CLI shows the real signature. The function that only queues an element for the height pass is `queueNaturalHeight`, and the pass's comment sits on the flush that runs it.
There was a problem hiding this comment.
Approval waits on an engineering owner's API decision; no blocking code issue remains at this head.
Next step
- An engineering owner decides the nine new
@astryxdesign/coreAPI rows (useCollapsible'striggerPropsandcontentProps, the newuseCollapsibleContentMotionhook with its two types, andCollapsible'shasLazyMount), the two draft module records and the proposedcomponent:CollapsibleFR11, including whetherheightPropertyshould follow the existingcustomPropertyoption name and how draft FR7 treats a theme that reduces motion for everyone. An engineering owner records approval by commenting/approve-spec <full head SHA>on this pull request; the author may do so if they are an engineering owner.
Non-blocking
- The description says
useCollapsibleContentMotion.tsis 244 lines; it is 242 lines at this head, still under the INV19 threshold. - The earlier note on draft FR7's theme case (line 78) still applies; the two other notes from the last review are fixed.
Claims and files checked
Review mode: full; reason: author-not-engowner
Claims
- Changeset (CLI): the hook template block wires its trigger and content with the new props, so the trigger names an element that stays while closed — verified (
CollapsibleHookUsage.tsx). - Changeset (CLI): a new animated-details block grows and fades in to the measured height and shrinks and fades out — verified (
CollapsibleContentMotionUsage.tsx). - Changeset (core):
useCollapsiblereturnstriggerPropsandcontentProps, and closed content mounts nothing — verified for the documented pattern, children gated onisOpen(useCollapsible.ts:163-179, tests). - Changeset (core):
useCollapsibleContentMotionis a separate import that keeps children through the close animation and writes the measured height — verified (module imports, tests, size check). - Changeset (core): under Reduce Motion a touch screen cross-fades and other pointers open and close at once — verified with the documented caller fade (tests; Chromium touch and desktop probes).
- Changeset (core):
CollapsiblehasLazyMountmounts children only while open — verified (Collapsible.tsx:515, lazy suite). - Changeset (core): a direct hook call takes one generated id, and Collapsible and Banner keep theirs — verified (one-id test; default stories pixel-identical with the same ids).
- Description: a whole row can be the trigger and a closed row is one empty element — verified (200 closed rows, 200 empty hidden content elements in Chromium).
- Description: phases last while the content's own CSS animation plays, and end before paint when none runs — verified (presence and phase tests).
- Description: the height is measured once per open and animated close, with the animation suppressed, in one pass per commit — verified (height tests; measuring each row at once fails the one-pass test).
- Description:
useCollapsible,CollapsibleandBannerimport none of the motion code — verified (imports). - Description:
hasLazyMountkeeps the empty region, keeps children through an animated close, and keeps focus return — verified (lazy, animated-layout and focus tests). - Description: first-load size grows +109 B (Collapsible) and +56 B (Banner) gzip, reference pages +0 — verified in substance (same minified deltas; +95 B and +51 B on the current base).
- Description:
useCollapsible.tsis 180 lines — verified; the motion module is 244 lines and 2,984 B gzip — false for the line count (242 lines), gzip verified. - Description: no behavior change for existing Collapsible and Banner callers, and no data attribute, token or theming target changes — verified (frames, generated API delta).
- Description: test counts 20 and 22, and each new test fails against the code it guards — counts verified; two of the guards re-checked by mutation.
- Description: build, typecheck, targeted test suites and strict lint pass — verified for the build, typecheck, targeted suites and lint re-run here.
- Description: real-browser frames of the grow and fade are not yet shown — accurate; Chromium probes here show the phases.
Files (28 of 28)
.changeset/the-usecollapsible-template-block-wires-its-trig-v9i6.md: clear.changeset/usecollapsible-returns-triggerprops-and-contentp-10sw.md: clearapps/sandbox/scripts/next-export-routes.json: clear (generated route entry)apps/storybook/stories/Collapsible.stories.tsx: clearapps/storybook/stories/CollapsibleA11y.stories.tsx: cleardocs/specs/components/Collapsible/Collapsible.spec.md: proposed FR11 and module rows wait on an owner decisiondocs/specs/components/Collapsible/modules/useCollapsible.spec.md: draft record waits on an owner decisiondocs/specs/components/Collapsible/modules/useCollapsibleContentMotion.spec.md: draft record waits on an owner decision; FR7 theme reading openinternal/shadcn-registry/routes.lock.json: clear (generated route entries)packages/cli/assets/templates/blocks/components/Collapsible/CollapsibleContentMotionUsage.doc.mjs: clearpackages/cli/assets/templates/blocks/components/Collapsible/CollapsibleContentMotionUsage.tsx: clearpackages/cli/assets/templates/blocks/components/Collapsible/CollapsibleHookUsage.tsx: clearpackages/cli/test/__golden__/no-icon-set/search-close.json: clear (golden)packages/cli/test/__golden__/no-icon-set/search-close.txt: clear (golden)packages/core/src/Banner/Banner.tsx: clearpackages/core/src/Collapsible/Collapsible.doc.mjs: clearpackages/core/src/Collapsible/Collapsible.test.tsx: clearpackages/core/src/Collapsible/Collapsible.tsx: new prop waits on an owner decision; code clearpackages/core/src/Collapsible/__tests__/Collapsible.a11y.states.ts: clearpackages/core/src/Collapsible/__tests__/useCollapsible.a11y.test.tsx: clearpackages/core/src/Collapsible/index.ts: new exports wait on an owner decisionpackages/core/src/Collapsible/useCollapsible.doc.mjs: clearpackages/core/src/Collapsible/useCollapsible.test.tsx: clearpackages/core/src/Collapsible/useCollapsible.ts: new returns wait on an owner decision; code clearpackages/core/src/Collapsible/useCollapsibleContentMotion.doc.mjs: clearpackages/core/src/Collapsible/useCollapsibleContentMotion.test.tsx: clearpackages/core/src/Collapsible/useCollapsibleContentMotion.ts: new hook waits on an owner decision; FR7 theme case at line 78 (non-blocking)packages/core/src/motion/animatedLayoutAdopters.test.tsx: clear
User need
A product sometimes needs a disclosure whose trigger is a whole list row: for
example, one step of a long run log, where the label, the detail, a live clock,
and a marker are one button with
aria-expanded.Collapsibledraws its own trigger button andchevron, so it cannot host that row.
useCollapsibleis the headless option,but it is only the open-state machine: no ids, no ARIA wiring, no content
presence. Each product hand-wires
aria-controls, and the usual pattern(
{isOpen && <div id=…>}) leavesaria-controlsnaming an element that isnot in the page while closed.
Collapsiblekeeps closed children mounted and hides them withdisplay: none, so every closed subtree still renders, and on a phone thatcosts real time on every list mount.
its own presence logic, and its own measured-height grow and fade. Each copy
drifts from the system's disclosure semantics and from Reduce Motion.
Problem and solution fit
useCollapsible. The hook returnstriggerPropsandcontentProps. Spreading them onto a<button>and analways-rendered content element makes one disclosure. Children render only
while
isOpen, so a closed row is one empty element.useCollapsibleContentMotion, its own import.It takes the
useCollapsibleresult and returnsisPresent,isEntering,isExiting, andcontentPropsto spread in place of the hook's. Its phaseslast while the content element's own CSS animation plays, and the children
stay (inert) until
animationend/animationcancel. With no runninganimation the phase ends before the frame paints. Under Reduce Motion the
shared policy decides: a fine pointer ends the phase at once, and a coarse
pointer waits for the content's cross-fade.
heightPropertymeasures thecontent's natural height once per open and animated close, with the
animation suppressed for the read, in one pass for every row a commit
changes.
useCollapsible,Collapsible, andBannerimport none of it.CollapsiblehasLazyMount. The same need for therendered component: an opt-in that mounts children only while open, keeps
the empty region so
aria-controlsresolves, keeps children through ananimatedLayoutclose, and keeps AR4 focus return.content id.
CollapsibleandBannertake theirs from it instead ofcalling
useIdagain, so each still takes one id from the page and everylater id keeps the value it has today. A direct hook call takes one new id.
proposed rows in
component:Collapsible, hook and component docs, theexisting
useCollapsibletemplate block moved to the new props, a newuseCollapsibleContentMotiontemplate block, two stories, and tests.Current specification
No current record decides the new API rows, so each row is for an owner
decision (
architecture:public-component-apiINV25). The proposed claims:module:Collapsible/useCollapsible(new,draft): FR1–FR3, AR1–AR2,OQ1–OQ2.
module:Collapsible/useCollapsibleContentMotion(new,draft): FR1–FR8,ORD1–ORD2, PR1–PR3, AR1–AR2, OQ1–OQ2.
component:Collapsible(current): a proposedcontent mountingconcept andFR11 (
hasLazyMount), basisproposal; the component lists both modulesand hands the hooks' wiring and motion to them.
Current authority the design follows:
spec:AST-055/DEC-4: a hook returnstriggerPropsto spread; that is thehook convention, separate from component render props.
architecture:public-component-apiINV21 (one API per job: the existingheadless disclosure hook is extended, not duplicated), INV2/DEC-1
(
useCollapsibleis the system's term; the CLI search already mapsuseDisclosureto it), DEC-2 (no newdata-*attribute: state reachesstyles as returned values plus
aria-expanded,hidden, andinert).architecture:component-import-boundariesINV7, INV10: the motion code isreachable only through its own hook, and a page without it grows by less
than 0.3 KB gzip (table below).
architecture:react-component-runtimeINV19:useCollapsible.tsis 180lines;
useCollapsibleContentMotion.tsis 242 lines and 2,978 B gzip ofsource, under the 300-line and 3 KB threshold. It reuses the shared Reduce
Motion policy and the shared realm; the Collapsible record says why no shared
engine plays a caller's CSS keyframes.
design:reduced-motionDR1, DR2, DR3: the companion takes its answer fromthe shared
reducedMotionFadepolicy, so a touch row cross-fades and anyother pointer changes at once.
architecture:react-component-runtimeINV2, INV3, INV5, INV6 (the routedconcern): the phase derives during render; the one layout effect names the
system it syncs (the content element's layout and CSS animations); the
animation listeners follow node replacement through the callback ref and
clean up with it.
spec:AST-105stays the owner of Core's own disclosure motion; nothing herechanges
animatedLayout.Public delta and caller burden
UseCollapsibleReturntriggerProps: {type: 'button'; 'aria-expanded'; 'aria-controls'; onClick}UseCollapsibleReturncontentProps: {id; hidden}@astryxdesign/core/CollapsibleexportuseCollapsibleContentMotion(collapsible, options?)UseCollapsibleContentMotionOptionsheightProperty?: `--${string}`UseCollapsibleContentMotionReturnisPresent,isEntering,isExitingisOpen,false,falseUseCollapsibleContentMotionReturncontentProps: {id; hidden; inert; ref}CollapsibleprophasLazyMount?: booleanfalseNo behavior change for existing callers of
CollapsibleandBanner: the newprop is off by default, existing returns keep their values, and their
generated ids keep their values. A direct
useCollapsiblecall now takes oneid from
useId, so ids React generates after it shift by one; the record andthe release note say so.
useCollapsiblewrites nothing to the DOM. Notheming target, token, or data attribute changes.
Before (the pattern the
useCollapsibletemplate block showed):After — a whole-row trigger:
After — the same row with a measured grow and fade:
New caller decisions: whether the content animates (one more hook call),
which custom property gets the height, the trigger's own paint and focus ring,
and keyframes keyed on the phases. To keep an own
onClick, compose withcomposeEventHandlers(yours, triggerProps.onClick).First-load size
pnpm size:pages --base 815282dc4 --page collapsible=Collapsible --page banner=Banner --unused-on collapsible,banner,minified / gzip bytes, for a page that renders the component without
useCollapsibleContentMotion:Both pages stay within the 0.3 KB (307 B) that an unused optional feature may
add (
architecture:component-import-boundariesINV10). The script reportsPASS for both.
Design and alternatives
Decisions for an owner (also open questions in the module records):
(this PR), vs a plugin value passed to
useCollapsible(
contentMotion: createCollapsibleContentMotion({heightProperty})), vs ananimatedLayoutoption that reports the change to the shared glide(
spec:AST-105FR1 allows a hook option; it keeps one disclosure motion inCore but needs a container handle and plays no grow and fade). The
companion keeps the motion code off every page that does not call it, and
keeps
useCollapsiblesmall. Either alternative can replace it before theAPI is approved.
useCollapsible(this PR;one hook for disclosure state, INV21) vs a separate
useDisclosurebuilt onit.
useCollapsibleContentMotion(alt.useDisclosureMotion),heightProperty(alt.contentHeightProperty),isPresent(alt.isMounted),isEntering/isExiting(alt. onecontentMotion: 'entering' | 'exiting' | null), andhasLazyMount(
useLayercalls the conceptlazyMount; the boolean-prop lint requiresis/hason component props; alt.isLazy). The prop and option types stayinline on the return types, as
useMenuHoverandusePopoverdo.policy's touch cross-fade holds the phase while the caller's fade plays; the
caller makes that animation an opacity-only fade of 200 ms or less.
data-state/data-motionattribute, which needs a current record(DEC-2).
caller's job; the alternative is a trigger ref in
triggerPropsso the hookmoves focus as
CollapsibleAR4 does.flushSyncfrom the content's ownanimationend, so no frame paints the children after their close animationeven without
animation-fill-mode: forwards.hasLazyMountcan split into its own pull request if the ownerprefers.
Evidence
useCollapsible.test.tsx(20): config parsing, the three modes, props andid wiring, closed content empty and hidden, mount and unmount counts,
controlled mode, and a return that holds only the headless basics.
useCollapsibleContentMotion.test.tsx(22): phases on mount / open / close/ reopen during close,
animationend,animationcancel, a descendant'sanimation, endless animations and transitions ignored, a replaced content
element; Reduce Motion with a fine and a coarse pointer, and the theme's
reduce-motion mark with each; the height measurement (suppressed read,
restore of an inline
animation-name, no write on mount, no read for aclose that drops its children or that Reduce Motion completes at once,
content-box, scaled ancestor), and one measurement pass for two accordionrows that change in the same commit.
Motion check fails both coarse-pointer tests; measuring each row at once
fails the one-pass test; measuring every close fails both no-measure tests;
dropping the phase hold fails 8 phase tests; and the earlier
useCollapsiblefails the headless-basics test.__tests__/useCollapsible.a11y.test.tsx:DISCLOSURE_PATTERNjsdom lanefor a whole-row trigger (closed, open, closed with content motion).
Collapsible.test.tsx:hasLazyMountclosed and empty, mount and unmount,default unchanged, AR4 focus return with the focused child unmounted; a
Collapsible takes exactly one generated id, so the ids after it keep their
values.
animatedLayoutAdopters.test.tsx:hasLazyMountkeeps children through ananimatedLayoutexit, then unmounts them.Collapsible.a11y.test.tsx: newlazy-closed-end-ltrstate (with itsA11y/Collapsible Disclosurestory for the Chromium lane).Core/Collapsible"Headless rows (useCollapsible)" (200 rows,measured grow and fade on theme motion tokens, with the Reduce Motion fade
for touch) and "Lazy mount". Template block:
useCollapsibleContentMotion — Animated Details.Not yet shown: real-browser frames of the grow and fade, and of the close's
last frame. I could not run a real browser locally; this pull request's Storybook
preview and CI carry the visual evidence.
Scope
Components: Collapsible, useCollapsible, useCollapsibleContentMotion
Testing
pnpm build(packages/core): pass.pnpm typecheck(packages/core: source, tests, docs): pass.typecheck:template-docsandtypecheck:strict(packages/cli): pass.typecheck(apps/storybook): pass.pnpm exec vitest run packages/core/src/Collapsible packages/core/src/Banner packages/core/src/motion/animatedLayoutAdopters.test.tsx packages/core/src/motion/reducedMotion.test.ts scripts/shared-identity.test.mjs apps/sandbox/src/route-manifest.test.ts internal/shadcn-registry/generate-shadcn-registry.test.mjs packages/cli/api/template:580 passed.
pnpm exec vitest run packages/cli/test/experimental-isolation.test.mjs:54 passed, with the
search closegoldens updated: the new hook's docmatches "close".
pnpm exec vitest run --project ui: 26,034 passed, 6 failed inpostinstall,DateTimeInput,TimeInput, andtimeFormat(locale hourcycles and day periods). The same 6 fail on the merge base in the same
environment.
pnpm exec vitest run --project node: 26,276 passed. The failures here arein suites that need a browser, a case-sensitive file system, or this
machine's home folder and CI history (theme editor and theme build, CI
tooling, packed-gather caches, setup nudges); none of them touches a file
this change edits, and the CI tooling and packed-gather failures also fail on
the merge base here. CI runs the node suites on Linux.
ASTRYX_STRICT_LINT=1 pnpm exec eslint <changed files>: clean.pnpm check:repo(includescheck:knowledgeandcheck:changesets): pass.pnpm size:pages(table above): PASS for both pages.pnpm specs:for --diff origin/main: followed the routedarchitecture:react-component-runtimeINV2, INV3, INV5, INV6.pnpm review:pre: 0 findings; items a, b, d, e, f, g apply (a and g wait onan owner; e is the new template block).
Writing rubric results
module:Collapsible/useCollapsible(new, draft):present tense.
options in OQ1–OQ2.
facts they prove.
decision is recorded yet.
#plusdigits,
/pull/,/issues/).and keep their options.
module:Collapsible/useCollapsibleContentMotion(new, draft):present tense.
options in OQ1–OQ2.
script, and the facts they prove.
decision is recorded yet; rejected shapes stay in this description.
#plusdigits,
/pull/,/issues/).and keep their options.
frames as an evidence gap, a template field.
component:Collapsible(current, amended):row, FR11, relationship lines, and verification row describe the component.
fits, in the present tense.
proposal(basis) andproposed(stability) markrows an owner has not approved.