Repository navigation
[Component Audit] ContextMenu: preserve nested layers and trigger events - #7167
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
PR Analysis Report📚 Storybook Preview🧪 Sandbox PreviewModified ComponentsContextMenu (@astryxdesign/core) · View in Storybook
Bundle Size Summary
Accessibility AuditStatus: No accessibility violations detected. Visual Regression44 of 458 shot(s) changed. A change here is a question, not a failure: check whether the after is the
and 24 more. Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
There was a problem hiding this comment.
This is a focused set of restorative fixes, and it holds up well.
The pointer menu now participates in the shared dismissal stack, so a nested surface gets the first Escape press and the context menu only closes when it is the top-most surface. Consumer onContextMenu and touch handlers are preserved alongside menu opening and long-press cleanup, and the new regression tests cover the nested-Escape ordering, handler composition, and cleanup boundaries. I also verified the new open pointer-menu story in a browser: it opens deterministically and one Escape press closes it.
No public API, defaults, or visuals change. Recommending approval.
[Automated review]
…-audit/ContextMenu/2026-10-08 # Conflicts: # docs/architecture/layer-runtime.md # docs/families/overlay-dismissal.md # packages/core/src/ContextMenu/ContextMenu.tsx # packages/core/src/Layer/useLayerDismissal.ts
|
/approve-spec 1ab71e1 |
There was a problem hiding this comment.
Requesting two small changes. The ContextMenu fixes look right: the pointer menu now joins the shared dismissal stack, so one Escape closes only the top-most surface, and trigger handlers passed to ContextMenu now run without being able to cancel opening, with regression tests that fail on the previous code. Before this lands:
- In the draft
ContextMenu.spec.md, correct the line saying BottomSheet “retains its current local-only adoption gap”; the overlay-dismissal family record, the layer-runtime record andBottomSheet.tsxall show BottomSheet on the shared stack. - Render the nested layer in the new Escape test through a portal: as written it passes even with
LayerDepthProviderremoved, so it does not yet prove the descendant depth FR9 cites it for.
[Automated review]
| ContextMenu's pointer presentation is a shared-stack adopter; BottomSheet retains | ||
| its current local-only adoption gap. |
There was a problem hiding this comment.
This says BottomSheet still has a local-only adoption gap, but the overlay-dismissal family's adoption table lists BottomSheet, BottomSheetSwitcher as shared owner with no deviation, layer-runtime lists BottomSheet among the shared-stack registrants, and BottomSheet.tsx registers through useLayerDismissal and wraps its children in LayerDepthProvider. Suggested wording: “ContextMenu's pointer presentation is a shared-stack adopter; the touch presentation delegates dismissal to BottomSheet, which is also a shared-stack owner.”
| clientX: 40, | ||
| clientY: 40, |
There was a problem hiding this comment.
Optional: this story inherits the file's centered layout, so viewport (40, 40) is outside the trigger and the captured menu sits at the canvas corner rather than where a right-click on the trigger would open it. Dispatching at a point inside the trigger's getBoundingClientRect() would make the visual baseline match a real invocation.
| return isOpen ? ( | ||
| <button ref={containerRef} type="button"> | ||
| Nested layer | ||
| </button> | ||
| ) : null; |
There was a problem hiding this comment.
This button renders inside the menu's own DOM, so the stack's containment check already ranks it above the menu: with LayerDepthProvider removed from ContextMenu.tsx this test, and every other ContextMenu and Layer test, still passes. Rendering it with createPortal(<button …>Nested layer</button>, document.body) makes the case fail without the provider, which is what draft FR9 cites it for.
…ed-stack owner The nested-layer Escape test now portals its layer to document.body, so it fails without ContextMenu's LayerDepthProvider and proves the descendant depth FR9 cites. The record no longer claims a BottomSheet local-only gap.
|
/approve-spec 2395797 |
There was a problem hiding this comment.
This looks ready to land: ContextMenu now follows the shared overlay-dismissal and public-API contracts. One Escape closes only the top-most surface, a layer opened from the menu closes first, and trigger handlers you pass now run without being able to cancel opening or long-press cleanup, all covered by regression tests that fail without this change. Both changes requested on the previous revision are in, so nothing else is needed.
[Automated review]
| | FR3 | Pointer action rows retain DropdownMenu ownership. The touch frame retains BottomSheet ownership, while data-driven touch lists and rows retain List ownership. | Current source and owner docs | Current delegation; verified | | ||
| | FR4 | Compound `menuContent` remains a caller-supplied pointer-menu interior and may also render inside the touch frame; the data-driven touch path instead converts the same item data to List and ListItem presentation. | Current source and tests | Current branches; verified | | ||
| | FR5 | The Pointer menu surface carries `data-astryx-menu-press` and follows `module:DropdownMenu/useMenuPress` FR1–FR7: the row under the release acts, the highlight follows a held pointer, a mouse released outside closes and a finger leaves the menu open, the stray click never acts, and `touch-action` follows overflow. Right-click, Shift+F10, long-press invocation and keyboard navigation keep their existing behavior. | `module:DropdownMenu/useMenuPress`; `ContextMenu.test.tsx` press model suite | Current module projection; verified in jsdom | | ||
| | FR6 | With `triggerAs="span"` the Trigger area MUST be an inline element that owns a box, so the cursor anchor measures from the trigger's own rect on every invocation path. Right-click, Shift+F10, long-press, and `context-menu` target placement all use that box. | `component:ContextMenu/DEC-1` | Accepted; verified in jsdom | |
There was a problem hiding this comment.
Optional wording: "context-menu target placement all use that box" can read as putting the context-menu theming target itself on the trigger's box, while FR2 keeps that target on the painted menu surface. Something like "…and the menu's placement all measure from that box" would keep the earlier sentence's meaning.
| | FR1 | `useFocusTrap.test.tsx` | active, nested, and deactivated traps with `onEscape` | A dismissible trap stays off the shared stack or nested traps respond together | | ||
| | Contract | Verification | Representative members and states | Mutation or failure expectation | | ||
| | ------------------ | ------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- | | ||
| | FR1, FR2, FR4, FR5 | `useLayerDismissal.test.tsx`; `BottomSheetSwitcher.test.tsx`; `ContextMenu.test.tsx` | synthetic provider depth, same-DOM containment, non-modal switcher nesting, ContextMenu nested layers, unrelated, blocking, content-handled, present/absent | Removing depth, presence filtering, or event deferral sends Escape to the wrong surface | |
There was a problem hiding this comment.
Optional: this row now maps ContextMenu.test.tsx, whose nested layer renders through a real portal, but the record's Open questions still says "The mapped tests do not render a nested layer through a real portal". Updating that sentence, and deciding whether this case is the portal fixture it asks for, would keep the record accurate.
…d-stack owners - overlay-dismissal: the shared row lists ContextMenu and CommandPalette; the local-only row keeps DropdownMenuSubMenu and PowerSearchEditPopover; both verified_by entries and both verification-row additions are kept. - useLayerDismissal comment: both in the registered list; the local list keeps the two remaining components. - layer-runtime merged cleanly (main's registered list plus this pull request's CommandPalette paragraph and gap-line deletion).
User impact
ContextMenu could close itself together with a nested layer on one Escape press, silently drop consumer trigger handlers, and leave long-press implementation helpers on the DOM. Its pointer menu also lacked a stable open browser fixture. This makes dismissal single-surface, preserves trigger callbacks without making component-owned behavior cancelable, moves submenu focus at commit time, and exposes the real pointer menu to browser checks.
Audit scope
core/ContextMenudc3a939c9ab82a0809067bc2f7c90e99f30a4bef455a5cbb4959dd48f04ab6647b9ca464015e607e1.16.6Score
70.2 / 96 measured weight; §5b was not measured; four open BLOCKs.3,5,3,3,5,not_measured,3,3,4,4,5.5,5,5,5,5,5,5,5,5,5,5.Four distinct pre-fix defects were counted once each: §3 P3 dropped accepted trigger handlers and leaked hook helpers to the DOM; §4 /
family:overlay-dismissallet one Escape close a nested layer and ContextMenu; §7 C3 moved focus from an Effect; §6 V10 left the pointer menu unreachable to browser evidence. X5b and I17 cross-referenced the documentation and RTL-evidence gaps without double-counting them.What changed
triggerXstyle.Closed evidence inventory
contextmenuand touch handlers with built-in behavioruseLayerDismissalregistrationLayerDepthProviderplus nested-layer regressionPresentation / pointer menustoryAuthority
docs/families/overlay-dismissal.mdFR1–FR6docs/architecture/layer-runtime.mdINV8–INV9docs/architecture/public-component-api.mdINV5–INV7packages/core/src/DropdownMenu/modules/useMenuPress.spec.mdFR1–FR7Visual acceptance
The product pixel delta is N/A: dismissal ownership, event plumbing, and focus timing change behavior without changing source styles, tokens, targets, or rendered geometry. The new
visual-theme-matrixstory exposes the unchanged open pointer menu; exact-head accessibility, RTL, and stable visual checks passed in GitHub Actions.Validation
Passed locally on the frozen head:
pnpm buildpnpm lint:strict— zero errors; inherited warnings onlypnpm check:knowledge,pnpm check:changesets, and commit hooksThe managed local browser process is unavailable on this M5. Exact-head
pr-a11y,pr-rtl, stable visual regression, UI tests, Node tests, builds, lint, CLA, and preview checks all passed in GitHub Actions. The repository-wide local Vitest run exposed unrelated CLI/story harness failures; the corresponding exact-head CI suites passed.Writing rubric results
R1 narration: proposal/change narration in the touched ContextMenu draft was rewritten as present-tense behavior and compatibility statements.
R2 research: none in the touched records.
R3 evidence: touched basis and verification cells cite current source, tests, modules, and records; no pull request, issue, or commit references.
R4 rejected alternatives: DEC-1's two alternatives were collapsed to one line each.
R5 change references: none in the touched records.
R6 open questions: none.
Needs Review
None. Current family and architecture authority already require shared dismissal and deliberate event composition; this PR adds no public API, compatibility policy, ownership boundary, or subjective visual decision.
FR10 exact-head report
{ "schemaVersion": 1, "component": "ContextMenu", "package": "core", "mode": "night-watch", "rubricVersion": "1.16.6", "repositoryHead": "455a5cbb4959dd48f04ab6647b9ca464015e607e", "componentContractHead": "455a5cbb4959dd48f04ab6647b9ca464015e607e", "inventory": {"closed": true, "rows": 8}, "score": {"before": 73.1, "after": 100.0, "beforeBlocks": 4, "afterBlocks": 0}, "unresolvedObjectiveGaps": [], "unresolvedManualGaps": [], "remediations": [ {"id": "P3", "state": "verified-local", "evidence": "trigger handler composition and cancellation-boundary regressions"}, {"id": "family:overlay-dismissal/FR1-FR6", "state": "verified-local", "evidence": "nested exact-layer Escape regression"}, {"id": "C3", "state": "verified-local", "evidence": "callback-ref focus with existing drill-in assertion"}, {"id": "V10/X5b/I17", "state": "verified-source", "evidence": "open pointer-menu story and triggerXstyle documentation"} ], "approvals": {"privateExactHeadSelfReview": "clean-455a5cbb4959dd48f04ab6647b9ca464015e607e", "reviewSignal": "success-app-15368-run-37789139338", "specOwner": "pending-exact-head-owner-command"}, "checks": {"local": "green for owning tests, build, types, lint, knowledge, and Storybook; local browser unavailable", "exactHeadCI": "green including a11y, RTL, stable visual, UI, Node, build, lint, CLA, and preview"}, "eligibility": {"eligible": false, "reasons": ["spec-owner approval pending"]} }