Repository navigation
fix(ContextMenu): position menu relative to context (scroll-follow + auto-flip) - #3866
Merged
Merged
Conversation
…llow + auto-flip Anchor the right-click menu to a zero-size point placed at the cursor *inside the trigger* and switch useLayer to context mode. The menu still appears under the cursor, but is now positioned relative to the trigger's context via CSS anchor positioning instead of fixed viewport coordinates: it follows the content on scroll and the browser auto-flips it against the viewport edges (position-area + flip fallbacks). positionRef is retained but now stores the cursor point in the trigger's local coordinate space rather than viewport coordinates. Resolves #3465.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
josephfarina
approved these changes
Jul 12, 2026
Contributor
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR No new or modified components detected. Bundle Size Summary
Accessibility AuditStatus: No accessibility violations detected. Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
cixzhang
marked this pull request as ready for review
July 12, 2026 19:24
This was referenced Jul 12, 2026
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes
ContextMenupositioning so the menu is anchored to the context (its trigger) rather than the page/viewport. The menu still opens under the cursor, but now:Resolves #3465.
Approach
The previous implementation used
useLayer({ mode: 'fixed' })and placed the menu at absolute viewport coordinates captured from the pointer — so it neither scroll-followed nor flipped.This PR keeps the cursor position but expresses it relative to the trigger's context using CSS anchor positioning:
<span>,aria-hidden) is rendered inside the trigger and positioned (vialeft/top) at the cursor point in the trigger's local coordinate space (offset from the trigger's top-left). Because the anchor lives inside the (scrollable) trigger, it moves with the content.useLayeris switched tomode: 'context', so the menu is anchored to that point withposition-area+position-try-fallbacks: flip-block, flip-inline, …. A zero-size point anchor makes the flip mirror cleanly around the cursor.positionRefis retained, but now stores the cursor point in the trigger's local space rather than viewport coordinates.No changes to
useLayerwere needed — context mode already supported everything. This is scoped to positioning only; the trigger wrapper andtriggerXstyle(the separatedisplay:contentsmigration, #3629) are left untouched.Handlers
getBoundingClientRect().(0,0)→ anchor to the trigger's bottom-left (local0, height), preserving the existing menus-8 behavior.Testing
pnpm -F @astryxdesign/core typecheck— cleanpnpm -F @astryxdesign/coreContextMenu suite — 31 passing (3 new: cursor-anchor exists with ananchor-name, anchor placed at the pointer's trigger-relative offset, keyboard invocation anchors to the trigger bottom-left)eslinton the changed files — cleanThe scroll-follow + auto-flip behavior is best validated interactively in a deployed build (jsdom does not implement CSS anchor positioning). Draft pending that check.