Skip to content

fix(ContextMenu): the menu paints in Safari when its trigger sits in a scroll container - #7369

Merged
cixzhang merged 2 commits into
meta:mainfrom
vjeux:contextmenu-cursor-anchor-box
Oct 13, 2026
Merged

cixzhang merged 2 commits into
meta:mainfrom
vjeux:contextmenu-cursor-anchor-box

Conversation

@vjeux

@vjeux vjeux commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

User impact

In Safari 26 (measured on iOS 26.2), a ContextMenu whose trigger sits inside a scroll container (any overflow: auto box) opens a menu that never paints. It is open, but nothing shows. Chromium paints it, and so does Safari with no scroller around the trigger.

Problem and solution fit

  • Why it fails: the menu is anchored to an empty box at the pointer (width: 0; height: 0). The default position-visibility: anchors-visible hides a box whose anchor is clipped, and WebKit counts an empty anchor inside a scroller as clipped.
  • Why it harms the task: the menu is the way to the trigger's actions.
  • Why that matters: context menus mostly live in scrolling lists and tables.

Expected behavior and authority

  • The Browser Support guide's Tier 1, Safari 26+: "Everything works, including CSS anchor positioning."
  • architecture:layer-runtime (current): layered UI must "stay positioned against its trigger".
  • component:ContextMenu FR1 (draft) describes it but does not govern.

Smallest restoration

  • cursorAnchor is 1px instead of 0, so WebKit sees it whenever its pixel is visible.
  • A point on the trigger's end edge (where a keyboard open lands) steps back by that pixel. A bare 1px box there adds scroll overflow and, against a scroller's edge, is clipped, hiding the menu in Chromium too.
  • Not positionVisibility: 'always': that paints the menu over unrelated content once a scroller clips its pointer position, unlike every other anchored layer and Chromium today.
  • Visible change: a pointer-opened menu starts 1px lower.
  • Supporting: a story with the trigger in a scroll container, "zero-size" → "1px" in the record, and a changeset.

Evidence

  • Reproduction before the change: iOS 26.2 Simulator Safari, new story. A long press opens the menu, and nothing paints.
  • Result after the change: it paints, hides while the box scrolls its anchor away, and paints again on return.
  • Representative unchanged path: Chromium 149 behaves as on main. A keyboard open on the scroller's edge adds no overflow.
  • Regression tests: the unit tests fail on main. The browser spec fails on main, with position-visibility: always, and with a bare 1px box.

Scope

  • One defect is restored.
  • Separable contradictory or unsettled tagalongs were removed or split.
  • No new public API, visual representation, default, or interaction model is hidden under the bug-fix label.
  • Public text and artifacts contain no internal Meta context.

Writing rubric results

  • R1: the one edited sentence is present tense; nothing else changed.
  • R2–R6: nothing added or touched.

Testing

  • pnpm vitest run --project ui packages/core/src/ContextMenu/: 55 passed. With main's ContextMenu.tsx, 3 fail (anchor box size, keyboard edge, end-edge step-back).
  • pnpm exec playwright test packages/core/src/ContextMenu/__tests__/ContextMenuCursorAnchor.a11y.browser.spec.ts --project=chromium, run against Storybook builds:
    • branch: 3/3 pass, ×5 repeats;
    • main code: the anchor-box test fails;
    • with position-visibility: always injected: the scroll test fails;
    • with a bare 1px anchor injected: the keyboard-edge test fails.
  • Pull-request CI does not run this spec. Only the release-check Chromium sweep does, and no CI job runs WebKit. Playwright WebKit cannot launch on my machine, so the WebKit states were checked in iOS 26.2 Simulator Safari: main and branch builds of the story, long press held, screenshots of each state.
  • Typecheck (core), eslint, prettier, check:knowledge, check:changesets, check:sync and the Storybook build are clean.

…a scroll container

ContextMenu anchors its menu to a box at the pointer, and that box was
empty. WebKit counts an empty anchor box inside a scroll container as
clipped, so the default `position-visibility: anchors-visible` hid the
open menu: it stayed open, focused and hit-testable, but never painted.

The cursor anchor is now 1px. A point on the trigger's end edge (where a
keyboard-invoked open lands) steps back by that pixel, so the anchor never
hangs past the trigger: there it would add scrollable overflow and be
clipped by a scroller whose edge meets the trigger's, hiding the menu in
Chromium too. The browser still hides the menu while a scroller clips the
pointer position, as it does for every other anchored layer.
@vercel

vercel Bot commented Oct 12, 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 12, 2026 10:33am UTC

Request Review

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

astracat-bot Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Oct 12, 2026, 10:57 AM UTC

The story's scrolling box holds nothing focusable, so axe flagged it
(scrollable-region-focusable). It takes a tab stop and a name, as the
other scrolling stories do.

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

Recommended for approval: giving the cursor anchor a 1px box, kept inside the trigger at its end edges, restores the menu in WebKit inside scroll containers, and in Chromium the only change is the disclosed 1px offset. The unit tests and the new browser spec cover it, and the spec passes in both Chromium and Playwright WebKit, where the old zero-size anchor leaves the open menu unpainted. Optionally, a desktop Safari 26 right-click check would cover the macOS path the description mentions, and note that pull-request CI does not run the new browser spec today (only the release-check Chromium sweep does).

[Automated review]

@github-actions

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR

🧪 Sandbox Preview

View Sandbox for this PR

No new or modified components detected.

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

42 of 448 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,129
TableRowExpansion Detail Panel neutral light 4,050

and 22 more.


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

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

CodeBunny approved at this head; CI green. Approved.

@cixzhang

Copy link
Copy Markdown
Contributor

/approve-spec b68db5c

@cixzhang
cixzhang enabled auto-merge (squash) October 13, 2026 01:37
@cixzhang
cixzhang merged commit 6227933 into meta:main Oct 13, 2026
44 checks passed
@vjeux
vjeux deleted the contextmenu-cursor-anchor-box branch October 13, 2026 01:50

This branch was successfully deployed

1 active deployment
Preview — b68db5c0 Deployed Oct 12, 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. needs:design-review Affects visuals — Design should review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants