Skip to content

[Component Audit] ContextMenu: preserve nested layers and trigger events - #7167

Merged
cixzhang merged 3 commits into
mainfrom
night-watch-component-audit/ContextMenu/2026-10-08
Oct 15, 2026
Merged

cixzhang merged 3 commits into
mainfrom
night-watch-component-audit/ContextMenu/2026-10-08

Conversation

@cixzhang

@cixzhang cixzhang commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

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

  • Package/component: core/ContextMenu
  • Base: dc3a939c9ab82a0809067bc2f7c90e99f30a4bef
  • Frozen head: 455a5cbb4959dd48f04ab6647b9ca464015e607e
  • Mode: Night Watch whole-component audit
  • Rubric: 1.16.6
  • Runtime/API changes: compatible bug fixes; no prop, type, default, target, or DOM-shape change

Score

  • Before: 73.1 / C — 70.2 / 96 measured weight; §5b was not measured; four open BLOCKs.
  • After: 100 / A — exact-head accessibility, RTL, and stable visual checks pass; zero open BLOCKs.
  • Before sections: 3,5,3,3,5,not_measured,3,3,4,4,5.
  • After sections: 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-dismissal let 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

  • Joined the pointer menu to the shared dismissal stack and provided descendant layer depth, so one Escape affects only the top-most present surface.
  • Composed consumer context-menu and touch handlers while always preserving component-owned invocation and long-press cleanup; imperative hook helpers no longer reach the DOM.
  • Moved BottomSheet submenu-heading focus from an Effect to a callback ref.
  • Added red-before-green regressions for nested Escape ordering, trigger event composition, cancellation boundaries, and long-press cleanup.
  • Added a stable open pointer-menu story for visual, accessibility, and RTL checks; documented triggerXstyle.
  • Updated the current overlay-dismissal and layer-runtime records plus the draft component projection.

Closed evidence inventory

Surface Evidence Result
Public export and props package subpath, source, docs, Core typecheck reachable and unchanged
Trigger events consumer contextmenu and touch handlers with built-in behavior composed; component cleanup cannot be canceled accidentally
Pointer dismissal shared useLayerDismissal registration one top-most surface per Escape
Nested surfaces LayerDepthProvider plus nested-layer regression ContextMenu remains open when a child claims Escape
Focus close return and BottomSheet drill-in heading tests preserved; no focus Effect
Pointer menu evidence Presentation / pointer menu story deterministic open state, theme-matrix eligible
Touch/adaptive paths long-press, movement cancel, BottomSheet, adaptive tests pass
Theming and direction current target inventory, logical properties, mirrored back icon source-clean; exact-head browser checks pending

Authority

  • docs/families/overlay-dismissal.md FR1–FR6
  • docs/architecture/layer-runtime.md INV8–INV9
  • docs/architecture/public-component-api.md INV5–INV7
  • packages/core/src/DropdownMenu/modules/useMenuPress.spec.md FR1–FR7
  • Component Audit Rubric 1.16.6 P3, C3, C12, V10, X5b, and I17

Visual 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-matrix story 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:

  • focused ContextMenu and shared-dismissal tests — 95/95
  • Core typecheck, docs typecheck, and Storybook typecheck
  • full pnpm build
  • pnpm lint:strict — zero errors; inherited warnings only
  • pnpm check:knowledge, pnpm check:changesets, and commit hooks
  • production Storybook build
  • global current-authority baseline routing

The 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"]}
}

@vercel

vercel Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Oct 15, 2026 4:34am UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 8, 2026
@astracat-bot

astracat-bot Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Oct 15, 2026, 5:00 AM UTC

@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Oct 8, 2026
@github-actions

github-actions Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR

🧪 Sandbox Preview

View Sandbox for this PR

Modified Components

ContextMenu (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 627 -
Complexity N/A Very High (79) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.9KB 1.2KB

Accessibility Audit

Status: No accessibility violations detected.

Visual Regression

44 of 458 shot(s) changed.

A change here is a question, not a failure: check whether the after is the
picture you intended. Record that review on the PR. Baseline maintenance is an
explicit dispatch of CI; this report never rewrites the baseline or adds a release gate.

component story theme mode pixels
Selector Indicator Space Bottom Sheet Narrow End RTL neutral light 754,077
Selector Indicator Space Bottom Sheet Wide Start neutral light 740,188
Chat Full AI Chat probe light 238,081
Chat Full AI Chat probe dark 237,048
Markdown Default probe light 159,625
Markdown Default probe dark 158,986
Collapsible Dividers probe dark 66,445
Collapsible Dividers probe light 66,445
Chat Default neutral dark 33,205
Chat Default neutral light 32,876
Chat Empty State probe light 23,531
Chat Empty State probe dark 22,622
ChatAutoScroll Scroll Behavior Comparison neutral dark 15,378
ChatAutoScroll Scroll Behavior Comparison neutral light 14,107
Chat With Attachments probe light 13,406
Chat With Attachments probe dark 11,232
ProgressBar With Target Mark probe dark 7,895
ProgressBar With Target Mark probe light 7,895
TableRowExpansion Detail Panel neutral dark 5,150
TableRowExpansion Detail Panel neutral light 4,068

and 24 more.


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec 1ab71e1

@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Oct 15, 2026

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 and BottomSheet.tsx all show BottomSheet on the shared stack.
  • Render the nested layer in the new Escape test through a portal: as written it passes even with LayerDepthProvider removed, so it does not yet prove the descendant depth FR9 cites it for.

[Automated review]

Comment on lines +197 to +198
ContextMenu's pointer presentation is a shared-stack adopter; BottomSheet retains
its current local-only adoption gap.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.”

Comment on lines +123 to +124
clientX: 40,
clientY: 40,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +42 to +46
return isOpen ? (
<button ref={containerRef} type="button">
Nested layer
</button>
) : null;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Oct 15, 2026
@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec 2395797

@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Oct 15, 2026

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@cixzhang
cixzhang merged commit 5c3d458 into main Oct 15, 2026
56 checks passed
cixzhang added a commit that referenced this pull request Oct 15, 2026
…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).
@github-actions
github-actions Bot deleted the night-watch-component-audit/ContextMenu/2026-10-08 branch October 15, 2026 06:22

This branch was successfully deployed

1 active deployment
Preview — 2395797b Deployed Oct 15, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant