Skip to content

feat(ContextMenu): createContextMenu and useContextMenu, a headless context menu (spec:AST-107 FR8) - #8693

Open
vjeux wants to merge 12 commits into
meta:mainfrom
vjeux:uikit/c20-headless-context-menu
Open

vjeux wants to merge 12 commits into
meta:mainfrom
vjeux:uikit/c20-headless-context-menu

Conversation

@vjeux

@vjeux vjeux commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

User need

A product that already renders an element, such as a list row, cannot give it a context menu without wrapping it. ContextMenu wraps its trigger, so a ListItem inside it gives ul > div > li, which HTML does not allow. Every divider then disappears (test).

Problem and solution fit

  • Why does the wrapper break the list? A li belongs directly in its list, and ContextMenu's trigger wrapper sits between them.
  • Why do the dividers go? A row draws its divider unless it is its parent's last child, and inside a wrapper every row is.
  • How does this help? createContextMenu attaches ContextMenu's own menu to an element without wrapping it, and useContextMenu does it from a component.

Current specification

spec:AST-107 FR8 defines both APIs. component:List FR13 gives a row a menu through its ref, keeping ul > li. component:ContextMenu FR10's gap sentence changes here, with its impact line and List's readiness row.

Public delta and caller burden

  • createContextMenu(element, {items | render, label?, isDisabled?, onOpenChange?, presentation?}) returns {open(at?), close(), destroy()}.
  • useContextMenu(ref, options) returns {open, close}, and takes menuContent JSX as ContextMenu does.
  • Both come from @astryxdesign/core/ContextMenu; the hook also from @astryxdesign/core/hooks.
  • A long press, a right click, Shift+F10 or the context-menu key opens the menu. Its rows, keys, presentations and dismissal are ContextMenu's.
  • The menu lives in the element's dialog, popover, shadow root or body. The element's markup is untouched.
  • ContextMenu's API and output do not change.
function Row() {
  const ref = useRef<HTMLLIElement>(null);
  useContextMenu(ref, {label: 'Actions for Inbox', items});
  return <ListItem ref={ref} label="Inbox" />;
}

Design and alternatives

ContextMenu's body becomes one internal root with two entries: ContextMenu, with its wrapper, and the attached menu the factory renders. Only ContextMenu.tsx and createContextMenu.tsx use that root.

  • Rejected: building ContextMenu on the factory now. FR10 asks for it, so its gap stays recorded.
  • Rejected: a second menu for the factory, which would fork ContextMenu's rows, keys and dismissal.

Still open: the lift under a finger (spec:AST-094 FR33) and a plain row's More actions button (component:List OQ2).

Evidence

  • Before: the new unit cases fail on main, where neither API exists (test).
  • After: they pass, and 10 Chromium cases pass (test).
  • Rows with a menu keep ul > li and every divider but the last row's (test).
  • Unchanged path: ContextMenu's, Table's and List's unit suites pass (test).

Scope

Components: ContextMenu, List

  • One capability is added.
  • Unrelated fixes, cleanup, and policy changes were removed or split.
  • Consumer docs, focused tests, and migration evidence ship with the feature.
  • Public text and artifacts contain no internal Meta context.

Testing

  • The last two commits change what an open and a menu's content do (test). At 9c07fda, an open moves the menu's container only when the element is in another dialog, popover, shadow root or body. It writes a theme attribute only when it changes.
  • A case with two menus checks that an open moves no node and writes no attribute (test). It fails with the code before, and with either half taken out (test).
  • A bottom sheet mounts its content as it opens and unmounts it after it closes, as ContextMenu's sheet does. So there render runs at each open and its cleanup after each close, and the docs say so. A case pins that, and fails when the sheet stays mounted (test).
  • At 58dfdab, useContextMenu renders menuContent at the menu's first open, not as it attaches. In a case with five rows, none renders its content before an open (test). The first open renders it once, and a reopen does not; the hook as it was rendered all five at attach (test).
  • At this head, the ContextMenu, List and Table unit directories pass 1,346 tests in 72 files (test). createContextMenu's interaction spec passes in Chromium, and the core typecheck and strict ESLint pass (test). The page sizes below are unchanged at this head (test).
  • An earlier commit corrects render's docs: in a popover it fills the menu once, at its first open, and its cleanup runs on destroy. Its case attaches menus to five rows, and none builds a menu or runs render before an open (test). With the menu's layer mounted at attach, that case fails (test).
  • pnpm preflight --browser at a80073e (CI unset, VITEST_MAX_WORKERS=12, ASTRYX_STRICT_LINT=1) reports "ready to flip" (test). Its unit steps passed 27,880 tests, and 30,407 with 3 expected fails (test). The node step skips 14 files and 108 tests and has 1 todo; this PR adds no skip or todo (test). Its accessibility step passed 187 and skipped 4, and its interaction step passed 2,038 and skipped 54 (test).
  • This head merges main 2999b15 into a80073e as a new commit. Of this PR's files, only the route lock changed on main, and the merge keeps both sides' routes.
  • After the merge, the ContextMenu, Table and List unit directories pass 1,342 tests in 72 files (test). The two repository guards this PR adds entries to pass 24 tests (test). The route-lock check, createContextMenu's interaction spec in Chromium, the core typecheck and strict ESLint pass (test).
  • pnpm size:pages --base 2999b1585 --head 06a9bca99 measures the first-load JavaScript gzip delta on the four reference pages of the import-boundaries record's INV10 (test). Gzip: docs +0 B, form +0 B, menu +333 B and table +351 B (test). The menu and table pages load ContextMenu, which this PR changes.
  • An attached open now reads layout once, then moves its anchor once. A new case counts the layouts that two opens force through a half-scale containing block, and checks where the anchor goes. At the test-only commit 9d2c608, the first open forces 2 (test). With the fix, each open forces at most 1, the layer's own read of the anchor (test).
  • Two new cases count the listeners a menu adds to the element, the document and the window, and expect none after destroy (test). They pass on the code as it was (test). Each fails when one removal is taken out: the keydown's, the long press's or the document press's (test).
  • pnpm exec vitest run --project ui packages/core/src/ContextMenu/ at a80073e: 125 tests pass (test). createContextMenu's interaction spec passes in Chromium there (test).
  • Found and fixed before this head: a first version wrote zero offsets before its read, and still forced 2 layouts on a repeat open (test). Strict ESLint also asked for latestRef in a useCallback's dependencies (test).
  • An earlier pnpm preflight --browser at 64721fa also reported "ready to flip" (test). The commit after it adds the two new hooks' routes, hooks/create-context-menu and hooks/use-context-menu, to internal/shadcn-registry/routes.lock.json. At 64721fa, pnpm -F @astryxdesign/docsite build stops at the route-lock check; from that commit on it passes (test).
  • A preflight before the branch's guard fixes failed only three repository guards: shared identity, the touch support bundle, and the doc inputs (test). A later commit fixes each.
  • pnpm test:interaction packages/core/src/ContextMenu/__tests__/createContextMenu.interaction.browser.spec.ts --project=chromium: 10 tests pass (test).
  • Two of those cases hold a finger on a list row for 1.2 s, through the harness's touch driver (test). The menu opens once, the lift clicks nothing, and Escape returns focus to the row (test). In WebKit, the same spec at 64721fa passes 10 of 10, both held-finger cases included (test). That run uses the repository's webkit-container.mjs and the Playwright image it names.
  • In a one-off control on the same story, rows wrapped in a div drew no divider (test). Chromium's accessibility tree ignored the wrappers and still showed four list items (test).
  • The four new unit files at main 9380b40 fail to load: neither API exists there (test).
  • pnpm check:knowledge: templates and records are aligned.

Writing rubric results

  • R1 narration: the changed record lines state what the system does, in the present tense.
  • R2 research: none.
  • R3 evidence: none; the change edits ContextMenu's FR10 gap, its current-state line and one ownership line, and List's readiness cell.
  • R4 rejected alternatives: none.
  • R5 change references: none.
  • R6 open questions: none new; component:List OQ2 stays open.
  • R7 project status: none in the changed lines; each states a gap as what the system does. Outside them, two lines from main still say "yet".

Drafted with an AI coding agent; the tests were run as described.

@vercel

vercel Bot commented Oct 27, 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 Dec 1, 2026 8:07am UTC

Request Review

@astracat-bot

astracat-bot Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
❓ Needs maintainer input (for maintainers only) Dec 3, 2026, 4:15 PM UTC

@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 pull request is on hold for a spec decision. createContextMenu and useContextMenu rely on spec:AST-107 FR8, which is still only in the open #8600; this head also adds requirements that main does not state yet (architecture:layer-runtime INV13, three springs.contextMenu* roles in spec:AST-094 FR4, the spec:AST-057 reword and component:ContextMenu DEC-2), and the stacked context request cites an AST-094 FR43 that no record contains. An engineering owner needs to provide the governing spec for the headless menu (landing #8600 with the FR43 text would do it) and to approve or reject these record changes by commenting /approve-spec 154a743b3fa668001077d82c8b3c9dcb37d70027 on this pull request; as an engineering owner, the author may do so too. Independently of that decision, please address the following:

  • Land the stacked predecessors and rebase, so that this diff is only the headless menu; it currently carries about 44,900 authored lines.
  • useContextMenu reads its ref once, so a row that mounts later or swaps its element gets no menu.
  • The hook's cleanup unmounts the menu's React root during React's commit, which React reports as a race in all six hook tests.
  • Under a held finger, the headless menu opens without the trigger lift that spec:AST-094 FR33 requires.
  • useContextMenu documents a presentation option that its type does not accept.

[Automated review]

Comment thread packages/core/src/hooks/useLongPress.ts Resolved
@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · 58dfdab

Storybook · Sandbox · built from this PR's head

Modified components

Component Size LoC Visual · A11y · RTL
ContextMenu · Storybook 111.4 kB (+328 B) · 19.9 kB CSS (0) 1,586 (+832) ✗ · ✓ · ✓
lab/MediaPlayer 🔴 111.4 kB (+80.0 kB) · 165 B CSS (0) — — · — · —
lab/ChatVirtualizer 🔴 113.3 kB (+55.1 kB) · 223 B CSS (0) — — · — · —
42 more components
Component Size LoC Visual · A11y · RTL
lab/ThreeDChart 🔴 47.7 kB (+42.5 kB) · 20 B CSS (0) — — · — · —
lab/MediaPlayerElement 🔴 47.6 kB (+40.6 kB) · 177 B CSS (0) — — · — · —
lab/ChatTypingIndicator 🔴 66.6 kB (+40.0 kB) · 612 B CSS (0) — — · — · —
lab/TabBar 🔴 124.5 kB (+39.6 kB) · 1.8 kB CSS (0) — — · — · —
lab/LineClamp 🔴 52.9 kB (+38.1 kB) · 168 B CSS (0) — — · — · —
lab/NavigationScreen 🔴 121.6 kB (+34.6 kB) · 1.5 kB CSS (0) — — · — · —
lab/NavigationStack 🔴 121.6 kB (+34.6 kB) · 1.5 kB CSS (0) — — · — · —
lab/CommentPin 🔴 92.4 kB (+28.7 kB) · 1.2 kB CSS (0) — — · — · —
lab/ListInput 🔴 129.7 kB (+28.0 kB) · 1.3 kB CSS (0) — — · — · —
richtext/RichTextEditor 🔴 339.1 kB (+24.8 kB) · 2.7 kB CSS (0) — — · — · —
richtext/RichTextView 🔴 315.2 kB (+24.2 kB) · 2.4 kB CSS (0) — — · — · —
lab/DiffViewer 🔴 123.3 kB (+23.6 kB) · 2.3 kB CSS (0) — — · — · —
lab/EmojiPicker 🔴 148.0 kB (+23.6 kB) · 751 B CSS (0) — — · — · —
lab/TransferList 🔴 163.7 kB (+19.6 kB) · 1.4 kB CSS (0) — — · — · —
lab/TransferListSelector 🔴 175.1 kB (+18.3 kB) · 1.6 kB CSS (0) — — · — · —
lab/Tour 🔴 126.7 kB (+14.6 kB) · 1.0 kB CSS (0) — — · — · —
lab/ChatReactionBar 🔴 145.7 kB (+10.7 kB) · 1.1 kB CSS (0) — — · — · —
lab/ChatEmojiPicker 🔴 144.0 kB (+10.5 kB) · 773 B CSS (0) — — · — · —
DateInput 🔴 222.3 kB (+8.2 kB) · 19.4 kB CSS (+250 B) — — · — · —
DateTimeInput 🔴 245.8 kB (+7.9 kB) · 21.1 kB CSS (+231 B) — — · — · —
lab/TabBarItem 🔴 11.6 kB (+7.7 kB) · 1.8 kB CSS (0) — — · — · —
lab/VideoPlayer 239.5 kB (+425 B) · 2.1 kB CSS (0) — — · — · —
TableHeaderCell 112.4 kB (+354 B) · 20.3 kB CSS (0) — — · — · —
Table 127.3 kB (+353 B) · 21.5 kB CSS (0) — — · — · —
TableCell 112.5 kB (+350 B) · 20.5 kB CSS (0) — — · — · —
lab/AudioPlayer 241.4 kB (+339 B) · 1.8 kB CSS (0) — — · — · —
Markdown 211.8 kB (+336 B) · 23.8 kB CSS (0) — — · — · —
lab/Comments 392.3 kB (+202 B) · 2.5 kB CSS (0) — — · — · —
PowerSearch 326.4 kB (+146 B) · 27.7 kB CSS (0) — — · — · —
lab/CommentThread 385.2 kB (+8 B) · 2.4 kB CSS (0) — — · — · —
lab/CommentComposer 192.2 kB (+4 B) · 1.9 kB CSS (0) — — · — · —
charts/Chart 268.7 kB (0) · 516 B CSS (0) — — · — · —
List 20.5 kB (0) · 3.0 kB CSS (0) — ✓ · ✓ · —
ListItem 84.5 kB (0) · 13.0 kB CSS (0) — ✓ · ✓ · ✓
lab/MediaCaptionsButton 230.7 kB (0) · 1.5 kB CSS (0) — — · — · —
lab/MediaFullscreenButton 230.7 kB (0) · 1.5 kB CSS (0) — — · — · —
lab/MediaPlaybackRate 230.7 kB (0) · 1.5 kB CSS (0) — — · — · —
lab/MediaPlayButton 230.7 kB (0) · 1.5 kB CSS (0) — — · — · —
lab/MediaSeekButton 230.7 kB (0) · 1.5 kB CSS (0) — — · — · —
lab/MediaTime 230.7 kB (0) · 1.5 kB CSS (0) — — · — · —
lab/MediaTimeSlider 230.7 kB (0) · 1.5 kB CSS (0) — — · — · —
lab/MediaVolume 230.7 kB (0) · 1.5 kB CSS (0) — — · — · —
Visual changes: 1 snapshot in 1 component

A change is a question for the reviewer, not a failure.

Component · story Before After Diff
ContextMenu · Default (neutral, dark) · same image also changed on another pull request, not proven from main before frame after frame diff frame

Inheritance checked against the 8 newest reports of other pull requests.

Package size: @astryxdesign/core 8.16 MB packed (+25.5 kB); no new dependencies.

API changes: core +19 · ~0 · −0

19 API changes (advisory)
Package Where Signature Usage
+ core . · Hooks · hook useContextMenu hook useContextMenu: (ref: RefObject<HTMLElement | null>, options: UseContextMenuOptions) => UseContextMenuResult import {useContextMenu} from '@astryxdesign/core'; useContextMenu(…)
+ core . · Functions · function createContextMenu function createContextMenu: (element: HTMLElement, initialOptions: CreateContextMenuOptions) => ContextMenuController import {createContextMenu} from '@astryxdesign/core'; createContextMenu(…)
+ core . · Types · type ContextMenuContentRenderer type ContextMenuContentRenderer = (container: HTMLElement) => (() => void) | undefined import type {ContextMenuContentRenderer} from '@astryxdesign/core'
+ core . · Types · interface ContextMenuController interface ContextMenuController import type {ContextMenuController} from '@astryxdesign/core'
+ core . · Types · interface ContextMenuPoint interface ContextMenuPoint import type {ContextMenuPoint} from '@astryxdesign/core'
+ core . · Types · type CreateContextMenuOptions type CreateContextMenuOptions = ContextMenuSharedOptions & ({ items: ReadonlyArray<ContextMenuOption>; render?: undefined } | { items?: undefined; render: ContextMenuContentRenderer }) import type {CreateContextMenuOptions} from '@astryxdesign/core'
+ core . · Types · type UseContextMenuOptions type UseContextMenuOptions = UseContextMenuSharedOptions & ({ items: ReadonlyArray<ContextMenuOption>; menuContent?: undefined } | { items?: undefined; menuContent: ReactNode }) import type {UseContextMenuOptions} from '@astryxdesign/core'
+ core . · Types · interface UseContextMenuResult interface UseContextMenuResult import type {UseContextMenuResult} from '@astryxdesign/core'
+ core ./ContextMenu · Also exported from an earlier entry point · ContextMenuContentRenderer ContextMenuContentRenderer (.) import {ContextMenuContentRenderer} from '@astryxdesign/core/ContextMenu'
+ core ./ContextMenu · Also exported from an earlier entry point · ContextMenuController ContextMenuController (.) import {ContextMenuController} from '@astryxdesign/core/ContextMenu'
+ core ./ContextMenu · Also exported from an earlier entry point · ContextMenuPoint ContextMenuPoint (.) import {ContextMenuPoint} from '@astryxdesign/core/ContextMenu'
+ core ./ContextMenu · Also exported from an earlier entry point · CreateContextMenuOptions CreateContextMenuOptions (.) import {CreateContextMenuOptions} from '@astryxdesign/core/ContextMenu'
+ core ./ContextMenu · Also exported from an earlier entry point · UseContextMenuOptions UseContextMenuOptions (.) import {UseContextMenuOptions} from '@astryxdesign/core/ContextMenu'
+ core ./ContextMenu · Also exported from an earlier entry point · UseContextMenuResult UseContextMenuResult (.) import {UseContextMenuResult} from '@astryxdesign/core/ContextMenu'
+ core ./ContextMenu · Also exported from an earlier entry point · createContextMenu createContextMenu (.) import {createContextMenu} from '@astryxdesign/core/ContextMenu'
+ core ./ContextMenu · Also exported from an earlier entry point · useContextMenu useContextMenu (.) import {useContextMenu} from '@astryxdesign/core/ContextMenu'
+ core ./hooks · Also exported from an earlier entry point · UseContextMenuOptions UseContextMenuOptions (.) import {UseContextMenuOptions} from '@astryxdesign/core/hooks'
+ core ./hooks · Also exported from an earlier entry point · UseContextMenuResult UseContextMenuResult (.) import {UseContextMenuResult} from '@astryxdesign/core/hooks'
+ core ./hooks · Also exported from an earlier entry point · useContextMenu useContextMenu (.) import {useContextMenu} from '@astryxdesign/core/hooks'

Touched components checked; for the full suites, add ci:run-visual for Visual, ci:run-rtl for RTL.


Generated by PR Enrichment workflow | 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 pull request is on hold for an engineering owner's spec decision. createContextMenu and useContextMenu cite spec:AST-107 FR8, which is still only in the open #8600; under a held finger the headless menu opens without the trigger lift that spec:AST-094 FR33 requires; and this head adds requirements that main does not state yet (architecture:layer-runtime INV13, three springs.contextMenu* roles in spec:AST-094 FR4, the spec:AST-057 reword and component:ContextMenu DEC-2). An engineering owner can provide the governing spec by landing #8600, and records the decision on the lift gap and these record changes by commenting /approve-spec 3ccf1bd734180a5740a55d233f0f83978bd29638 on this pull request; as an engineering owner, the author may do so too. Independently of that decision, please address the following:

  • Land the stacked predecessors and rebase, so that this diff is only the headless menu; it currently carries about 45,700 authored lines.
  • useContextMenu reads its ref once, so a row that mounts later or is replaced by another node gets no menu.
  • The hook's cleanup unmounts the menu's React root during React's commit.
  • Opens run in a layout effect rather than in the request handler, and that effect names no external system.
  • useContextMenu documents a presentation option that its type does not accept.

[Automated review]

Comment thread packages/core/src/hooks/useLongPress.ts Resolved

@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 pull request is on hold for an engineering owner's spec decision. spec:AST-107 FR8 now governs createContextMenu and useContextMenu, but three things still need an owner: the hook's internal updateContextMenu and bridgeContextMenu paths, which FR6 and FR8 do not admit (the description's own question about a public update(options)); the headless menu opening under a held finger without the trigger lift spec:AST-094 FR33 requires; and record changes main does not state yet (architecture:layer-runtime INV13, three springs.contextMenu* rows in spec:AST-094 FR4, the spec:AST-057 reword and component:ContextMenu DEC-2). An engineering owner records that decision by commenting /approve-spec 7780ee91a17092061ec89a96f47020af939cd92b on this pull request, or amends the records first; as an engineering owner, the author may do so too. Independently of that decision, please address the following:

  • Land the stacked predecessors and rebase, so that this diff is only the headless menu; it currently carries about 46,100 authored lines.
  • useContextMenu reads its ref once, so a row that mounts later or is replaced by another node gets no menu.
  • The hook's cleanup unmounts React roots during React's commit, which React reports in each of the hook's nine tests.
  • FR8 says ContextMenu is built on createContextMenu, but ContextMenu still renders the shared internal view directly.
  • useContextMenu is not exported from @astryxdesign/core/hooks, where AST-107's public contract imports it.
  • Opens run in a layout effect that fires onOpenChange, and the new effects do not name what they synchronize.
  • Closing returns focus to whatever had it before the open, not to the element as FR8 states.

[Automated review]

vjeux added a commit to vjeux/astryx that referenced this pull request Oct 27, 2026
…its menu in the element's dialog, popover or shadow root; its rows at the menu's layer depth; main dcdb356) into ContextMenu on the factory

createContextMenu.tsx: meta#8693's container placement, rows context and
wrapper access, with this branch's request core (attachContextMenuRequests)
in place of the factory's own context request.

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

Incremental review of 7780ee9..64b21e0; prior findings carried: spec_authority, authored_loc, context, user_impact, api, mechanism, evidence_by_spec_claim, concrete_defects, disposition

This pull request is still on hold for an engineering owner's spec decision: the hook's internal updateContextMenu, bridgeContextMenu and rows-context paths, which spec:AST-107 FR6 and FR8 do not admit (the description's own question about a public update(options)); the headless menu opening under a held finger without the trigger lift spec:AST-094 FR33 requires; and record changes main does not state yet (architecture:layer-runtime INV13, three springs.contextMenu* rows in spec:AST-094 FR4, the spec:AST-057 reword and component:ContextMenu DEC-2). An engineering owner records that decision by commenting /approve-spec 64b21e03bd8939f7b45120ad5cae02b5b32340e4 on this pull request, or amends the records first; as an engineering owner, the author may do so too. This push makes the menu usable inside a modal dialog, an open popover and a shadow root, but independently of the hold, please address the following:

  • Inside an open Drawer, or any dialog or popover with a transform, the menu now opens away from the pointer (off-screen in a Drawer), because its position: fixed cursor anchor is laid out against that container.
  • Land the stacked predecessors and rebase, so that this diff is only the headless menu (about 46,300 authored lines today, and about 2,130 for the menu alone).
  • useContextMenu reads its ref once, so a row that mounts later or is replaced gets no menu, and its cleanup unmounts React roots during React's commit.
  • FR8 says ContextMenu is built on createContextMenu and that focus returns to the element on close (inside a shadow root it now falls to the body), and useContextMenu is still missing from @astryxdesign/core/hooks.

[Automated review]

vjeux added a commit to vjeux/astryx that referenced this pull request Oct 28, 2026
…pec; the factory closes on a press outside, mouse or finger) into ContextMenu on the factory

createContextMenu.test.tsx: both sides add cases at its end; this keeps
both, and the finger's outside-press cases take the file's shared clock
epoch, since the touch-model cases before them have moved the gesture
host's clock past a fresh 100 s.

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

Full review of 6f8ba32; the incremental delta could not be read: the merge of main resolves a conflict inside the verification map of packages/core/src/ContextMenu/ContextMenu.spec.md, a spec record, and CodeBunny's earlier review could not be loaded.

This pull request is on hold for an engineering owner's spec decision: spec:AST-107 FR8 governs createContextMenu and useContextMenu, but an owner must approve or reject the hook's internal updateContextMenu, bridgeContextMenu and rows-context paths (FR6 says the hook has no behavior of its own), the headless menu opening under a held finger without the lift spec:AST-094 FR33 requires, and the record changes main does not state yet (architecture:layer-runtime INV13, three springs.contextMenu* rows in AST-094 FR4, the spec:AST-057 reword and DEC-2 in component:ContextMenu). An engineering owner records that decision by commenting /approve-spec 6f8ba32b8d4d4702ca9f64293d0c1b6d0909ffa2 on this pull request, or amends the records first; as an engineering owner, the author may do so too. Independently of the hold, please address the following:

  • Land the stacked predecessors and rebase, so this diff is the headless menu alone (about 46,400 authored lines today).
  • Inside an open Drawer, or any transformed dialog or popover, the menu opens away from the pointer, off-screen in a Drawer.
  • FR8 says ContextMenu is built on createContextMenu and that focus returns to the element on close, and useContextMenu is still missing from @astryxdesign/core/hooks.
  • useContextMenu reads its ref once and unmounts React roots during React's commit, and scripts/touch-support-bundle.test.mjs and pressableCoverage.test.ts fail on this head.

[Automated review]

vjeux added a commit to vjeux/astryx that referenced this pull request Oct 28, 2026
…ng its roots without unmounting them inside React's commit; the factory's anchor through a transformed dialog) into ContextMenu on the factory

createContextMenu.tsx: the wrapper access carries both this branch's view
setter and meta#8693's destroy for React callers; teardown destroys this
branch's request core. useContextMenu.tsx: the rows slot's host goes at
once and its root renders nothing.
Main rewrote List's readiness cell to state gaps instead of build
status. The resolution keeps main's cell and states this branch's row
menu facts in that form: what opens a row menu, and its FR13 gap.
The FR10 gap and its current-state line said that the factory and the
hook ship and that ContextMenu still takes its own invocation. They now
state what the system does: the three share one menu, and ContextMenu
takes its invocation on its own wrapper element.
@vjeux
vjeux force-pushed the uikit/c20-headless-context-menu branch from 5e9e161 to 64721fa Compare November 27, 2026 13:18
@cixzhang cixzhang added ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) ci:run-a11y Run the accessibility suite on this PR; write access, next push (AST-030 FR12) labels Nov 27, 2026
@cixzhang

Copy link
Copy Markdown
Contributor

/approve-spec 64721fa

@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Nov 27, 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.

Approval waits on an engineering owner's decision on two points that this head's /approve-spec does not cover: whether createContextMenu may ship while ContextMenu keeps its own invocation instead of being built on it, which spec:AST-107 FR8 and architecture:public-component-api INV21 still require, and whether both APIs may ship without the live template example that architecture:knowledge-contracts INV28 and spec:AST-107 FR5 ask for. An engineering owner, the author included, can settle both by replying on this pull request or by amending those records on main.

Whatever the decision, these need changes:

  • Newly live check: fixedOffsetOfClientPoint (ContextMenu.tsx:279-294) interleaves left/top writes with getBoundingClientRect reads, so every open lays the page out at least twice against architecture:react-component-runtime INV18; read the 1 px anchor once at its current offset and write once.
  • Newly live check: useContextMenu.tsx:153 writes the latest-value ref latestRef inside a layout effect, while INV3 routes such a ref only through useCommittedRef.
  • Miss: createContextMenu.tsx:317 keeps {element, handleRef} in React state, which INV1 forbids for DOM nodes; build the attachment once in the factory and pass it down.
  • The dense docs at createContextMenu.doc.mjs:138 say render fills the menu when it opens, but it runs once at attach and its cleanup runs at destroy.
  • Miss: no test fails when a listener (the element's keydown, the long-press recognizer, or the open menu's document mousedown) survives destroy, which spec:AST-107 FR8's verification asks for.
Claims and files checked

Review mode: full; reason: history

Claims:

  • Changeset: attaches ContextMenu's menu to any element without wrapping it - verified (the factory's host is never a child of the element)
  • Changeset: a ListItem row keeps ul > li and its dividers - verified by code (host appended outside the list; ListItem's :last-child divider rule); tests not run here
  • Changeset: opens on a long press, a right click, Shift+F10 or the context-menu key - verified by code (the shared context-request module)
  • Changeset: destroy removes every listener and node it added - verified by enumerating the element listeners, the recognizer, the host and the root's effects; no test counts listeners (finding above)
  • Title: a headless context menu per AST-107 FR8 - partly: FR8's clause that ContextMenu is built on the factory does not hold yet (owner question)
  • Description: a ContextMenu around a ListItem gives ul > div > li and drops the dividers - verified (the control test and ListItem's divider rule)
  • Description: both APIs come from the ContextMenu entry, the hook also from the hooks entry - verified (both entry files)
  • Description: the menu lives at the end of the element's dialog, popover, shadow root or body, and the element's markup is untouched - verified by code
  • Description: ContextMenu's API and output do not change - verified by reading the changed files and the modules that import ContextMenu
  • Description: only ContextMenu.tsx and createContextMenu.tsx use the shared root - verified by a repository search for both names
  • Description: the lift under a finger and the More actions button stay open - verified (recorded as gaps, approved at this head)
  • Description: test runs and counts, preflight results, red-first runs, merge state, one-off controls and rubric results - reported (CI has not run at this head)
  • Description: public text carries no internal context - verified (residue scan over the added lines, commits, title, body and branch: no match)

Files:

  • .changeset/createcontextmenu-element-options-attaches-conte-k1sw.md - clear
  • apps/storybook/stories/ContextMenu.stories.tsx - clear
  • docs/specs/components/ContextMenu/ContextMenu.spec.md - clear (approved at this head)
  • docs/specs/components/List/List.spec.md - clear (approved at this head)
  • packages/cli/foundation/doc-compiler/inputs.test.mjs - clear
  • packages/core/src/ContextMenu/ContextMenu.doc.mjs - clear
  • packages/core/src/ContextMenu/ContextMenu.tsx - forced layout on open; bypass of the factory held for an owner
  • packages/core/src/ContextMenu/tests/createContextMenu.interaction.browser.spec.ts - clear
  • packages/core/src/ContextMenu/contextMenuRequests.ts - clear
  • packages/core/src/ContextMenu/contextMenuRows.tsx - clear
  • packages/core/src/ContextMenu/createContextMenu.doc.mjs - dense render description
  • packages/core/src/ContextMenu/createContextMenu.ssr.test.tsx - clear
  • packages/core/src/ContextMenu/createContextMenu.test.tsx - no listener check after destroy
  • packages/core/src/ContextMenu/createContextMenu.tsx - DOM node in state; long header (non-blocking)
  • packages/core/src/ContextMenu/index.ts - clear
  • packages/core/src/ContextMenu/useContextMenu.doc.mjs - clear
  • packages/core/src/ContextMenu/useContextMenu.test.tsx - clear
  • packages/core/src/ContextMenu/useContextMenu.tsx - latest-value ref in a layout effect; long header (non-blocking)
  • packages/core/src/List/tests/ListItemContextMenu.test.tsx - clear
  • packages/core/src/hooks/index.ts - clear
  • scripts/touch-support-bundle.test.mjs - clear

Automated review (maintainer link)

The docsite build checks the ShadCN routes it generates against a
reviewed lock. This branch adds two public hooks, so the build stopped
at that check. The lock now lists their two routes,
hooks/create-context-menu and hooks/use-context-menu. No other route
is added, removed or changed.
@cixzhang

Copy link
Copy Markdown
Contributor

/approve-spec 266812b

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

Approval waits on an engineering owner's decision on two points that this pull request's approved record edits do not settle: whether createContextMenu may ship while ContextMenu keeps its own invocation instead of being built on it, which spec:AST-107 FR8 and architecture:public-component-api INV21 still require, and whether both APIs may ship without the live template example that architecture:knowledge-contracts INV28 and spec:AST-107 FR5 ask for. An engineering owner, the author included, can settle both by replying on this pull request or by amending those records on main.

The new commit's route lock entries are fine. Whatever the decision, these need changes:

  • Newly live check: fixedOffsetOfClientPoint (ContextMenu.tsx:279-294) interleaves left/top writes with getBoundingClientRect reads, so every open lays the page out at least twice against architecture:react-component-runtime INV18; read the 1 px anchor once at its current offset and write once.
  • Newly live check: useContextMenu.tsx:153 writes the latest-value ref latestRef inside a layout effect, while INV3 routes such a ref only through useCommittedRef.
  • Miss: createContextMenu.tsx:317 keeps {element, handleRef} in React state, which INV1 forbids for DOM nodes; build the attachment once in the factory and pass it down.
  • The dense docs at createContextMenu.doc.mjs:138 say render fills the menu when it opens, but it runs once at attach and its cleanup runs at destroy.
  • Miss: no test fails when a listener (the element's keydown, the long-press recognizer, or the open menu's document mousedown) survives destroy, which spec:AST-107 FR8's verification asks for.
  • Miss: ContextMenu.tsx is shared with Table and grows by the attached-menu code every ContextMenu and Table page loads, so architecture:component-import-boundaries INV10 asks for base-against-head first-load gzip deltas on the docs, form, menu and table reference pages.
Claims and files checked

Review mode: incremental; reason: none

Changed rules (1): "When the issued head equals the head of CodeBunny's latest complete review" - checked: the issued head and the latest reviewed head differ, so the same-head rule does not govern this review; no finding

Claims:

  • Changeset: attaches ContextMenu's menu to any element without wrapping it - verified (the factory's host is never a child of the element)
  • Changeset: a ListItem row keeps ul > li and its dividers - verified by code (the host is appended outside the list; ListItem's divider rule); tests not run here
  • Changeset: opens on a long press, a right click, Shift+F10 or the context-menu key - verified by code (the shared context-request module)
  • Changeset: destroy removes every listener and node it added - verified by enumerating the element listeners, the recognizer, the host and the root's effects; no test counts listeners (finding above)
  • Title: a headless context menu per AST-107 FR8 - partly: FR8's clause that ContextMenu is built on the factory does not hold yet (owner decision)
  • Description: a ContextMenu around a ListItem gives ul > div > li and drops the dividers - verified (the control test and ListItem's divider rule)
  • Description: both APIs come from the ContextMenu entry, the hook also from the hooks entry - verified (both entry files)
  • Description: the menu lives at the end of the element's dialog, popover, shadow root or body, and the element's markup is untouched - verified by code
  • Description: ContextMenu's API and output do not change - verified by reading the changed files and the modules that import ContextMenu
  • Description: only ContextMenu.tsx and createContextMenu.tsx use the shared root - verified by a repository search (2 files)
  • Description: the lift under a finger and the More actions button stay open - verified (recorded as gaps, approved)
  • Description: the last commit adds the two hook routes to the route lock and changes no other file - verified (that commit changes one file, 10 added lines)
  • Description: the merge with main is clean, and of this pull request's files only the route lock changed there - verified at the current main
  • Description: the docsite build stops at the route lock check before the last commit and passes at this head - reported (CI's docsite build runs the same check; it has not run at this head)
  • Description: test runs and counts, preflight results, red-first runs, the WebKit run, one-off controls and rubric results - reported (CI has not run at this head)
  • Description: public text carries no internal context - verified (residue scan over the added lines, commits, title, body and branch: no match)

Files:

  • .changeset/createcontextmenu-element-options-attaches-conte-k1sw.md - clear
  • apps/storybook/stories/ContextMenu.stories.tsx - clear
  • docs/specs/components/ContextMenu/ContextMenu.spec.md - clear (approved at this head)
  • docs/specs/components/List/List.spec.md - clear (approved at this head)
  • internal/shadcn-registry/routes.lock.json - clear
  • packages/cli/foundation/doc-compiler/inputs.test.mjs - clear
  • packages/core/src/ContextMenu/ContextMenu.doc.mjs - clear
  • packages/core/src/ContextMenu/ContextMenu.tsx - forced layout on open; first-load numbers missing; bypass of the factory held for an owner
  • packages/core/src/ContextMenu/tests/createContextMenu.interaction.browser.spec.ts - clear
  • packages/core/src/ContextMenu/contextMenuRequests.ts - clear
  • packages/core/src/ContextMenu/contextMenuRows.tsx - clear
  • packages/core/src/ContextMenu/createContextMenu.doc.mjs - dense render description
  • packages/core/src/ContextMenu/createContextMenu.ssr.test.tsx - clear
  • packages/core/src/ContextMenu/createContextMenu.test.tsx - no listener check after destroy
  • packages/core/src/ContextMenu/createContextMenu.tsx - DOM node in state; long header (non-blocking)
  • packages/core/src/ContextMenu/index.ts - clear
  • packages/core/src/ContextMenu/useContextMenu.doc.mjs - clear
  • packages/core/src/ContextMenu/useContextMenu.test.tsx - clear
  • packages/core/src/ContextMenu/useContextMenu.tsx - latest-value ref in a layout effect; long header (non-blocking)
  • packages/core/src/List/tests/ListItemContextMenu.test.tsx - clear
  • packages/core/src/hooks/index.ts - clear
  • scripts/touch-support-bundle.test.mjs - clear

Automated review (maintainer link)

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

Changes requested. An engineering owner's approval at this head settles the spec side, including ContextMenu keeping its own invocation and both APIs shipping without a live template example for now. These code and evidence items remain before approval:

  • Newly live check: fixedOffsetOfClientPoint (ContextMenu.tsx:279-294) interleaves left/top writes with getBoundingClientRect reads, so every open lays the page out at least twice against architecture:react-component-runtime INV18; read the 1 px anchor once at its current offset and write once.
  • Newly live check: useContextMenu.tsx:153 writes the latest-value ref latestRef inside a layout effect, while INV3 routes such a ref only through useCommittedRef.
  • Miss: createContextMenu.tsx:317 keeps {element, handleRef} in React state, which INV1 forbids for DOM nodes; build the attachment once in the factory and pass it down.
  • The dense docs at createContextMenu.doc.mjs:138 say render fills the menu when it opens, but it runs once at attach and its cleanup runs at destroy.
  • Miss: no test fails when a listener (the element's keydown, the long-press recognizer, or the open menu's document mousedown) survives destroy, which spec:AST-107 FR8's verification asks for.
  • Miss: ContextMenu.tsx is shared with Table and grows by the attached-menu code every ContextMenu and Table page loads, so architecture:component-import-boundaries INV10 asks for base-against-head first-load gzip deltas on the docs, form, menu and table reference pages.
Claims and files checked

Review mode: same-head; reason: none

Title: feat(ContextMenu): createContextMenu and useContextMenu, a headless context menu (spec:AST-107 FR8)

Changed rules (0): none since the earlier review at this head

Claims:

  • Changeset: attaches ContextMenu's menu to any element without wrapping it - verified (the factory's host is never a child of the element)
  • Changeset: a ListItem row keeps ul > li and its dividers - verified by code (the host is appended outside the list; ListItem's divider rule); tests not run here
  • Changeset: opens on a long press, a right click, Shift+F10 or the context-menu key - verified by code (the shared context-request module)
  • Changeset: destroy removes every listener and node it added - verified by enumerating the element listeners, the recognizer, the host and the root's effects; no test counts listeners (finding above)
  • Title: a headless context menu per AST-107 FR8 - verified for the factory and hook; ContextMenu's move onto the factory is an owner-accepted gap
  • Description: a ContextMenu around a ListItem gives ul > div > li and drops the dividers - verified (the control test and ListItem's divider rule)
  • Description: both APIs come from the ContextMenu entry, the hook also from the hooks entry - verified (both entry files)
  • Description: the menu lives at the end of the element's dialog, popover, shadow root or body, and the element's markup is untouched - verified by code
  • Description: ContextMenu's API and output do not change - verified by reading the changed files and the modules that import ContextMenu
  • Description: only ContextMenu.tsx and createContextMenu.tsx use the shared root - verified by a search of Core's source
  • Description: the lift under a finger and the More actions button stay open - verified (recorded as gaps, approved)
  • Description: the last commit adds the two hook routes to the route lock and changes no other file - verified (that commit changes one file, 10 added lines)
  • Description: the merge with main is clean, and of this pull request's files only the route lock changed there - verified at the current main
  • Description: the docsite build stops at the route lock check before the last commit and passes at this head - reported (CI's docsite build runs the same check; it has not run at this head)
  • Description: test runs and counts, preflight results, red-first runs, the WebKit run, one-off controls and rubric results - reported (CI has not run at this head)
  • Description: public text carries no internal context - verified (scan over the added lines, commits, title, body and branch: no match)

Files:

  • .changeset/createcontextmenu-element-options-attaches-conte-k1sw.md - clear
  • apps/storybook/stories/ContextMenu.stories.tsx - clear
  • docs/specs/components/ContextMenu/ContextMenu.spec.md - clear (approved at this head)
  • docs/specs/components/List/List.spec.md - clear (approved at this head)
  • internal/shadcn-registry/routes.lock.json - clear
  • packages/cli/foundation/doc-compiler/inputs.test.mjs - clear
  • packages/core/src/ContextMenu/ContextMenu.doc.mjs - clear
  • packages/core/src/ContextMenu/ContextMenu.tsx - forced layout on open; first-load numbers missing
  • packages/core/src/ContextMenu/tests/createContextMenu.interaction.browser.spec.ts - clear
  • packages/core/src/ContextMenu/contextMenuRequests.ts - clear
  • packages/core/src/ContextMenu/contextMenuRows.tsx - clear
  • packages/core/src/ContextMenu/createContextMenu.doc.mjs - dense render description
  • packages/core/src/ContextMenu/createContextMenu.ssr.test.tsx - clear
  • packages/core/src/ContextMenu/createContextMenu.test.tsx - no listener check after destroy
  • packages/core/src/ContextMenu/createContextMenu.tsx - DOM node in state; long header (non-blocking)
  • packages/core/src/ContextMenu/index.ts - clear
  • packages/core/src/ContextMenu/useContextMenu.doc.mjs - clear
  • packages/core/src/ContextMenu/useContextMenu.test.tsx - clear
  • packages/core/src/ContextMenu/useContextMenu.tsx - latest-value ref in a layout effect; long header (non-blocking)
  • packages/core/src/List/tests/ListItemContextMenu.test.tsx - clear
  • packages/core/src/hooks/index.ts - clear
  • scripts/touch-support-bundle.test.mjs - clear

Automated review (maintainer link)

An attached open measured its anchor at two offsets, so each open laid
out twice, with writes between its reads. One case counts the layouts
that two opens force through a scaled containing block, and checks
where the anchor goes.

Two cases count the listeners a menu adds to the element, the document
and the window, and expect none after destroy: its keys, its long press
and its document press while open.
An attached open measured its anchor at two offsets, with writes
between its reads. It now reads the element's box and the anchor's
drawn box where the anchor is, and then writes the anchor's offsets
once. The anchor's drawn size against its layout size gives the
containing block's scale, and its current offsets give the origin.

useContextMenu's latest options go through useCommittedRef. The factory
builds the element's attachment once, instead of keeping it in React
state. The dense docs say that `render` fills the menu once, as it
attaches, and that its cleanup runs on destroy.
createContextMenu's docs said that `render` fills the menu once, as it
attaches. It runs when the menu's layer mounts, at the first open, so a
closed menu that never opened builds nothing. The docs and the comment
now say so.

A new case attaches menus to five rows. It checks that none built a
menu or ran `render` before an open, that the first open runs it once,
that a reopen does not run it again, and that destroy runs its cleanup
once.
@cixzhang

cixzhang commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

/approve-spec 5d57d6d

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

Changes requested. The spec side is settled: an engineering owner approved this head. Two fixes remain:

  • Miss: an open re-appends the menu's host whenever it is not its parent's last child (createContextMenu.tsx:397-401), so in a list with a menu on every row the open's reads follow that DOM move and the layer reads again after the anchor write, laying the page out twice against react-component-runtime INV18; move the host only when its parent changes, and add a case with two menus.
  • render's docs and comments (createContextMenu.doc.mjs:38, :138, createContextMenu.tsx:64-66, :349-351) promise one fill at the first open and one cleanup at destroy, but with presentation: 'bottom-sheet' (or 'adaptive' on a touch screen) the sheet remounts its content, so render runs at every open and its cleanup at every close; document that or keep the sheet's content mounted, and add a sheet case.

Both findings sit on the inline threads at these lines. CI has not run the tests at this head, since this pull request is a draft.

Claims and files checked

Review mode: same-head; reason: none

  • changed rules (0): none
  • Live title, "feat(ContextMenu): createContextMenu and useContextMenu, a headless context menu (spec:AST-107 FR8)": verified (both APIs ship from the ContextMenu folder with the signatures the gesture-hooks spec gives)
  • Release note: the factory attaches the menu to any element without a wrapper: verified (createContextMenu.tsx:248-255, :397-404)
  • Release note: a ListItem row keeps ul > li and its dividers: verified by the unit and browser cases' assertions (ListItemContextMenu.test.tsx, the interaction spec); not run here
  • Release note: a long press, a right click, Shift+F10 or the context-menu key opens it: verified (gestures/contextRequest.ts:175, :199)
  • Release note: destroy removes every listener and node it added: verified; the element's listeners and long press go with the request (contextMenuRequests.ts:88-95), the open menu's document listeners and the host with the teardown (createContextMenu.tsx:476-496); the page's shared gesture host is shared infrastructure
  • Description: a ContextMenu wrapper gives ul > div > li: verified (control case)
  • Description: every divider disappears inside a wrapper: reported
  • Description: signatures and entry points: verified (ContextMenu/index.ts, hooks/index.ts, the package's exports map)
  • Description: rows, keys, presentations and dismissal are ContextMenu's: verified (shared root)
  • Description: the menu lives at the end of the element's dialog, popover, shadow root or body: verified (createContextMenu.tsx:248-255)
  • Description: ContextMenu's API and output do not change: verified by reading
  • Description: only ContextMenu.tsx and createContextMenu.tsx use the shared root: verified (a search of the head's packages and apps for the attached menu: those two files)
  • Description: render fills the menu once, at its first open, and cleans up on destroy: false under the bottom sheet
  • Description: each attached open forces at most one layout: false when the open moves the host
  • Description: the new listener cases expect none after destroy: verified (case content); their mutation results reported
  • Description: the merge keeps both sides' routes, and only the route lock overlaps: verified
  • Description: first-load gzip deltas docs +0 B, form +0 B, menu +333 B, table +351 B: reported
  • Description: unit, interaction, WebKit, preflight, typecheck and lint runs: reported
  • .changeset/createcontextmenu-element-options-attaches-conte-k1sw.md: clear
  • apps/storybook/stories/ContextMenu.stories.tsx: clear
  • docs/specs/components/ContextMenu/ContextMenu.spec.md: clear (approved)
  • docs/specs/components/List/List.spec.md: clear (approved)
  • internal/shadcn-registry/routes.lock.json: clear (generated)
  • packages/cli/foundation/doc-compiler/inputs.test.mjs: clear
  • packages/core/src/ContextMenu/ContextMenu.doc.mjs: clear
  • packages/core/src/ContextMenu/ContextMenu.tsx: the open's read and write sequence (finding 1)
  • packages/core/src/ContextMenu/__tests__/createContextMenu.interaction.browser.spec.ts: clear
  • packages/core/src/ContextMenu/contextMenuRequests.ts: clear
  • packages/core/src/ContextMenu/contextMenuRows.tsx: clear
  • packages/core/src/ContextMenu/createContextMenu.doc.mjs: render timing (finding 2)
  • packages/core/src/ContextMenu/createContextMenu.ssr.test.tsx: clear
  • packages/core/src/ContextMenu/createContextMenu.test.tsx: the layout case covers one menu only (finding 1); no sheet case (finding 2)
  • packages/core/src/ContextMenu/createContextMenu.tsx: host move (finding 1), render comments (finding 2)
  • packages/core/src/ContextMenu/index.ts: clear
  • packages/core/src/ContextMenu/useContextMenu.doc.mjs: clear
  • packages/core/src/ContextMenu/useContextMenu.test.tsx: clear
  • packages/core/src/ContextMenu/useContextMenu.tsx: clear
  • packages/core/src/List/__tests__/ListItemContextMenu.test.tsx: clear
  • packages/core/src/hooks/index.ts: clear
  • scripts/touch-support-bundle.test.mjs: clear

Automated review (maintainer link)

An open re-appended the menu's container whenever it was not its
parent's last child, so in a list with a menu on every row an open
moved a node before its layout reads. The container now moves only
when the element is in another dialog, popover, shadow root or body,
and the theme attributes it mirrors are written only when they change.

A bottom sheet mounts its content as it opens and unmounts it after it
closes, as ContextMenu's sheet does, so there `render` runs at each
open and its cleanup after each close. The docs and comments say so.

Two cases: two menus, where an open moves no node and writes no
attribute; and a bottom sheet, which fills at each open and cleans up
after each close.
useContextMenu rendered each element's menuContent as it attached, so a
list with a menu on every row rendered every row's content on mount.
It now keeps the content, and renders it when the factory fills the
menu at its first open, as the factory's own render does. It stays
rendered after, so a reopen does not render it again.

A new case attaches menus to five rows. None renders its content
before an open; the first open renders it once, and a reopen does not.
@cixzhang

cixzhang commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

/approve-spec 58dfdab

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

Approved pending CI. Both findings from the last review are fixed: an open in a list no longer moves the menu's container or writes theme attributes, and render's docs now say a bottom sheet fills the menu at each open and cleans up after each close. CI has not run on this head yet because the pull request is a draft; it runs once the pull request is marked ready for review, and the merge guard waits for it.

  • Optional: the header of contextMenuRows.tsx still says the rows "stay rendered" so the first row is there when focus starts; since useContextMenu now renders menuContent at the first open, "render at the menu's first open and stay rendered after" would match the code (inline note).
Claims and files checked

Review mode: incremental; reason: none

  • changed rules (0): none
  • Title: the pull request adds createContextMenu and useContextMenu, the headless context menu the gesture-hooks spec defines: verified (both ship from the ContextMenu folder with the spec's signatures)
  • Release note: the factory attaches ContextMenu's menu to any element without wrapping it: verified (the host goes in the element's dialog, popover, shadow root or body, createContextMenu.tsx:256-263, :409-415; the dialog, popover and shadow-root cases assert the menu is outside the element)
  • Release note: the hook does the same from a component: verified (useContextMenu.tsx:200-239; useContextMenu.test.tsx:195)
  • Release note: a ListItem row keeps ul > li and its dividers: verified by test content (ListItemContextMenu.test.tsx asserts only li children and the same row classes as rows without a menu; the browser case reads each row's border)
  • Release note: a long press, a right click, Shift+F10 or the context-menu key opens it: verified (gestures/contextRequest.ts:174-200; cases at createContextMenu.test.tsx:191, :219, :227, :736)
  • Release note: destroy removes every listener and node it added: verified (enumerated: the host, its React root, the element's keydown and contextmenu listeners, the long-press recognizer, the open menu's document listeners; createContextMenu.tsx:488-508, contextMenuRequests.ts:88-95; cases at :557, :571, :779); the page's shared gesture host is shared infrastructure
  • Description: a ContextMenu wrapper gives ul > div > li: verified (control case in ListItemContextMenu.test.tsx)
  • Description: every divider disappears inside a wrapper: reported (a one-off browser control); the reason follows from ListItem's last-child divider rule
  • Description: signatures, options, returns and entry points: verified (createContextMenu.tsx:75-107, useContextMenu.tsx:52-75, ContextMenu/index.ts, hooks/index.ts, the package's exports map)
  • Description: rows, keys, presentations and dismissal are ContextMenu's: verified (shared ContextMenuRoot)
  • Description: ContextMenu's API and output do not change: verified by reading the changed file and its direct importers (ContextMenu renders ContextMenuRoot with no attachment; same trigger, anchor classes and surface)
  • Description: only ContextMenu.tsx and createContextMenu.tsx use the shared root: verified (search of packages, apps and internal at the head for the attached menu: those two files; contextMenuRequests.ts imports only a request type)
  • Description: an open moves the menu's container only when the element is in another dialog, popover, shadow root or body, and writes a theme attribute only when it changes: verified (createContextMenu.tsx:231-248, :409-415; two-menu case at createContextMenu.test.tsx:442)
  • Description: a bottom sheet fills the menu at each open and cleans up after each close, and the docs say so: verified (DropdownMenu/MenuBottomSheet.tsx:43-65; createContextMenu.doc.mjs:38, :138; case at createContextMenu.test.tsx:487)
  • Description: useContextMenu renders menuContent at the first open, once, and not again on a reopen: verified (useContextMenu.tsx:92-133; case at useContextMenu.test.tsx:158)
  • Description: in a popover render fills the menu once, at its first open, and its cleanup runs on destroy; no menu is built before an open: verified (case at createContextMenu.test.tsx:390)
  • Description: an attached open reads layout once, then moves its anchor once: verified (ContextMenu.tsx:795-821; case at createContextMenu.test.tsx:589)
  • Description: the two listener cases expect none after destroy: verified (case content at :571, :779); their mutation results: reported
  • Description: the head contains the merge of the base branch, only the route lock overlapped, and both sides' routes are kept: verified (history; the route lock gains only the two new routes)
  • Description: the pull request adds no skipped or todo test: verified (search of the diff)
  • Description: first-load gzip deltas docs +0 B, form +0 B, menu +333 B, table +351 B, unchanged at this head: reported
  • Description: unit, interaction, WebKit, preflight, red-first, typecheck, lint and knowledge-check runs and counts: reported
  • .changeset/createcontextmenu-element-options-attaches-conte-k1sw.md: clear
  • apps/storybook/stories/ContextMenu.stories.tsx: clear
  • docs/specs/components/ContextMenu/ContextMenu.spec.md: clear (owner-approved at this head)
  • docs/specs/components/List/List.spec.md: clear (owner-approved at this head)
  • internal/shadcn-registry/routes.lock.json: clear (generated route lock)
  • packages/cli/foundation/doc-compiler/inputs.test.mjs: clear
  • packages/core/src/ContextMenu/ContextMenu.doc.mjs: clear
  • packages/core/src/ContextMenu/ContextMenu.tsx: clear
  • packages/core/src/ContextMenu/__tests__/createContextMenu.interaction.browser.spec.ts: clear
  • packages/core/src/ContextMenu/contextMenuRequests.ts: clear
  • packages/core/src/ContextMenu/contextMenuRows.tsx: clear (non-blocking: header says the rows stay rendered, now true from the first open)
  • packages/core/src/ContextMenu/createContextMenu.doc.mjs: clear (bottom-sheet timing documented)
  • packages/core/src/ContextMenu/createContextMenu.ssr.test.tsx: clear
  • packages/core/src/ContextMenu/createContextMenu.test.tsx: clear (two-menu and bottom-sheet cases added)
  • packages/core/src/ContextMenu/createContextMenu.tsx: clear (the host moves only when its container changes; non-blocking: long file header)
  • packages/core/src/ContextMenu/index.ts: clear
  • packages/core/src/ContextMenu/useContextMenu.doc.mjs: clear
  • packages/core/src/ContextMenu/useContextMenu.test.tsx: clear (first-open render case added)
  • packages/core/src/ContextMenu/useContextMenu.tsx: clear (menuContent renders at the first open; non-blocking: long file header)
  • packages/core/src/List/__tests__/ListItemContextMenu.test.tsx: clear
  • packages/core/src/hooks/index.ts: clear
  • scripts/touch-support-bundle.test.mjs: clear

Automated review (maintainer link)

Comment on lines +10 to +13
* hands createContextMenu a `render` for its rows. The rows stay rendered
* into a host the menu's container adopts, so the first enabled row is
* there when focus starts, and they read the menu's own row context, open
* state and layer

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.

Non-blocking (comment accuracy): since useContextMenu renders menuContent at the menu's first open, the rows no longer "stay rendered" from attach. Suggested: "The rows render into a host the menu's container adopts, at the menu's first open, and stay rendered after; they read the menu's own row context, open state and layer."

@cixzhang
cixzhang marked this pull request as ready for review December 1, 2026 09:07

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

Approved at 58dfdab (CodeBunny APPROVE at this head after push and body, CI green incl. pr-a11y, Specs ✓, device evidence clear; cx-8201 exempt).

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

Changes requested, and one owner decision. Two claims in this pull request's text are false at this head; the last review could already see both and missed them. Approval also waits on an engineering owner ruling whether spec:AST-107 FR8's "destroy removes every listener it added" lets the page-wide listeners below stay, or amending FR8.

  • Miss: The changeset says "destroy removes every listener and node it added", but attaching and destroying the first menu on a page leaves seven document and window listeners (React's own selectionchange from the factory's root, the layer gesture counter's four and the input-modality tracker's two; reproduced locally), and both listener-count tests attach and destroy another menu before they count, so reword the changeset and the destroy docs (createContextMenu.doc.mjs:81, :147, createContextMenu.tsx:105) to say what destroy removes.
  • Miss: The description says "The element's markup is untouched", but attaching writes data-astryx-touch-action="manipulation" on the element until destroy (reproduced locally and in Chromium on the head's Storybook), which also turns off double-tap zoom there, so reword it, and the same sentence in createContextMenu.doc.mjs:25, :135, useContextMenu.doc.mjs:22 and createContextMenu.tsx:23, to say the menu adds no wrapper or child.

CI passes at this head.

Claims and files checked

Review mode: same-head; reason: none

  • changed rules (3): Claim bounding in one round; A claim bounded by a record is bounded; The rules above still apply
  • Claim bounding in one round: two findings over the whole pull request, every case listed: the destroy claim (React's root listener, the layer gesture counter, the input-modality tracker) and the markup claim (the touch-action mark; on iOS WebKit, the selection lock's inline styles during a hold); both marked as missed
  • A claim bounded by a record is bounded: checked the title's and the description's record citations (gesture-hooks spec FR8, List FR13, ContextMenu FR10) against the current records; no finding
  • The rules above still apply: checked every case the changeset and description list (below); findings as above
  • Live title "feat(ContextMenu): createContextMenu and useContextMenu, a headless context menu (spec:AST-107 FR8)": verified (both ship from the ContextMenu folder with the spec's signatures)
  • Release note: the factory attaches ContextMenu's menu to an element without wrapping it: verified (createContextMenu.tsx:255-263, :409-415; dialog, popover and shadow-root cases)
  • Release note: the hook does the same from a component: verified (useContextMenu.tsx:200-239; useContextMenu.test.tsx:129)
  • Release note: a ListItem row keeps ul > li and its dividers: verified (ListItemContextMenu.test.tsx; the browser case reads each row's border and passes in CI; capture here)
  • Release note: a long press, a right click, Shift+F10 or the context-menu key opens it: verified (gestures/contextRequest.ts:92-106, :172-200; cases createContextMenu.test.tsx:191, :219, :227, :736; capture here)
  • Release note: destroy removes every listener and node it added: false (seven page listeners stay after a first menu's destroy; no node stays)
  • Description: ContextMenu wraps its trigger, giving ul > div > li: verified (control case in ListItemContextMenu.test.tsx)
  • Description: every divider disappears inside a wrapper: reported (the author's browser control); the reason is ListItem's last-child rule (List/ListItem.tsx:270-272)
  • Description: the gesture-hooks spec defines both APIs, List gives a row a menu through its ref, ContextMenu's gap sentence changes: verified against the current records
  • Description: signatures, options, returns and entry points: verified (createContextMenu.tsx:75-107, useContextMenu.tsx:52-75, ContextMenu/index.ts, hooks/index.ts; CI's API report lists the same rows)
  • Description: rows, keys, presentations and dismissal are ContextMenu's: verified (shared ContextMenuRoot)
  • Description: the menu lives in the element's dialog, popover, shadow root or body: verified (createContextMenu.tsx:255-263)
  • Description: the element's markup is untouched: false (data-astryx-touch-action while attached)
  • Description: ContextMenu's API and output do not change: verified by reading ContextMenu.tsx and CI's visual report (11 of 12 shots unchanged; the changed one is the story's dashed demo border, also changed on another pull request)
  • Description: only ContextMenu.tsx and createContextMenu.tsx use the shared root: verified (search of packages, apps and internal at the head)
  • Description: an open moves the container only when the element's container changed and writes a theme attribute only when it changed: verified (createContextMenu.tsx:231-248, :409-415; case :442)
  • Description: a bottom sheet fills the menu at each open and cleans up after each close, and the docs say so: verified (case :487; createContextMenu.doc.mjs:38, :138)
  • Description: useContextMenu renders menuContent at the first open, once: verified (case useContextMenu.test.tsx:158)
  • Description: in a popover render fills the menu once at its first open, cleanup on destroy, no menu before an open: verified (case createContextMenu.test.tsx:390)
  • Description: an attached open reads layout once, then moves its anchor once: verified (ContextMenu.tsx:795-821; case :589)
  • Description: the two listener cases expect none after destroy: verified as test content, which counts only after a first menu (finding above); their mutation results: reported
  • Description: the head contains the base-branch merge, and the route lock keeps both sides' routes: verified (history; CI's docsite build passes)
  • Description: the pull request adds no skipped or todo test: verified (search of the diff)
  • Description: first-load gzip deltas docs +0 B, form +0 B, menu +333 B, table +351 B: reported
  • Description: unit, interaction, WebKit, preflight, red-first, typecheck, lint and knowledge-check runs and counts: reported; CI at this head runs and passes the unit, interaction (with WebKit), accessibility, typecheck, lint and docsite jobs
  • .changeset/createcontextmenu-element-options-attaches-conte-k1sw.md: finding (destroy claim)
  • apps/storybook/stories/ContextMenu.stories.tsx: clear
  • docs/specs/components/ContextMenu/ContextMenu.spec.md: clear (owner-approved at this head)
  • docs/specs/components/List/List.spec.md: clear (owner-approved at this head)
  • internal/shadcn-registry/routes.lock.json: clear (generated route lock)
  • packages/cli/foundation/doc-compiler/inputs.test.mjs: clear
  • packages/core/src/ContextMenu/ContextMenu.doc.mjs: clear
  • packages/core/src/ContextMenu/ContextMenu.tsx: clear
  • packages/core/src/ContextMenu/__tests__/createContextMenu.interaction.browser.spec.ts: clear
  • packages/core/src/ContextMenu/contextMenuRequests.ts: clear
  • packages/core/src/ContextMenu/contextMenuRows.tsx: clear (non-blocking: header wording)
  • packages/core/src/ContextMenu/createContextMenu.doc.mjs: finding (markup and destroy wording)
  • packages/core/src/ContextMenu/createContextMenu.ssr.test.tsx: clear
  • packages/core/src/ContextMenu/createContextMenu.test.tsx: finding (listener cases skip the first-menu case)
  • packages/core/src/ContextMenu/createContextMenu.tsx: finding (header and destroy JSDoc wording; non-blocking: long header)
  • packages/core/src/ContextMenu/index.ts: clear
  • packages/core/src/ContextMenu/useContextMenu.doc.mjs: finding (markup wording)
  • packages/core/src/ContextMenu/useContextMenu.test.tsx: clear
  • packages/core/src/ContextMenu/useContextMenu.tsx: clear (non-blocking: long header)
  • packages/core/src/List/__tests__/ListItemContextMenu.test.tsx: clear
  • packages/core/src/hooks/index.ts: clear
  • scripts/touch-support-bundle.test.mjs: clear

Automated review (maintainer link)

name: 'element',
type: 'HTMLElement',
description:
'The element that owns the menu, already on the page, such as a list row. Its markup is untouched: the menu renders outside it, so a `li` row keeps its list valid.',

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.

Miss (the last review saw this line): attaching writes data-astryx-touch-action="manipulation" on the element until destroy (the context request's long press asks the gesture host for it), so double-tap zoom is off on the element and its markup is not untouched. Reproduced locally and in Chromium on the head's Storybook, where every ListItem row with a menu carries it. Suggested: "The element that owns the menu, already on the page, such as a list row. The menu adds no wrapper or child: it renders outside the element, so a li row keeps its list valid. While attached, the element carries a touch-action mark." The same sentence is at :135, in useContextMenu.doc.mjs:22 and in the header of createContextMenu.tsx (:23).

});

it('destroy removes every listener it added, the keys and the document press while open included (spec:AST-107 FR8)', () => {
// A first menu adds what the document keeps for every menu after it.

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 first attach and destroy hides exactly the case that makes the release note's destroy claim false: the listeners it leaves are the seven a page keeps after its first menu. Once the wording (or the owner's reading of the gesture-hooks spec's destroy clause) is settled, a case without this step that asserts which listeners stay would pin it. The same step is at :781.

This branch was successfully deployed

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

Labels

ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) ci:run-a11y Run the accessibility suite on this PR; write access, next push (AST-030 FR12) CLA Signed This label is managed by the Meta Open Source bot. needs:design-review Affects visuals — Design should review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants