Skip to content

ContextMenu: anchor the menu to the right-click target (scroll-follow + auto-flip) instead of fixed positioning #3465

Closed

Description

@cixzhang

Problem

ContextMenu currently positions its menu at a fixed coordinate captured from the pointer/keyboard invocation point. Because the layer is fixed rather than anchored to the element the menu belongs to:

  • The menu does not move with its target during scroll — if the underlying content scrolls while the menu is open, the menu stays put and detaches visually from the item it acts on.
  • There is no auto-flip: when the menu would overflow the viewport near an edge, it can't reposition (flip/shift) the way an anchored layer can.

Proposal

Make the ContextMenu layer contextual (anchored) instead of fixed:

  1. Take the target of the right-click (the element under the invocation point) and apply an anchor to it.
  2. Position the menu relative to that anchor, so the menu tracks the item during scroll and can auto-flip/shift when near viewport edges.

This aligns ContextMenu with the anchored-layer behavior used elsewhere (CSS anchor positioning), giving correct scroll-follow and edge collision handling.

Context

Split out from review discussion on the touch/keyboard invocation work (#3392). That PR intentionally kept the existing fixed positioning; this issue tracks the anchoring follow-up so it can be designed and reviewed on its own.

Part of the accessibility & keyboard-management program (#3343).

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions