Skip to content

ContextMenu should stop propagating mouse events #7525

@Irfy

Description

@Irfy

I have wrapped the title of a Tab in order to give it a ContextMenu capability on right-click. When a MenuItem in that ContextMenu is clicked, the click appears to propagate to the Tab itself, causing its activation (parent Tabs onChange handler is invoked).

This makes it impossible to handle MenuItem clicks of an inactive Tab, without activating it.

What I've tried

Manually stopping the propagation of the click event in the MenuItem onClick handler stops propagation too early -- the ContextMenu does not close in that case.

Manually activating a different Tab in the MenuItem onClick handler is also too early, the Tab receives the propagated click after the MenuItem onClick handler finishes.


Motivation & Background: When you right-click an inactive Chrome tab and click Duplicate, it opens a new tab right of the original tab and activates the new tab. I am unable to clone this (desirable) behavior with Blueprint due to the propagation issue.

Workaround:

  • mouseEvent.customFlag = true in the MenuItem onClick handler
  • Then check for this flag in the Tabs onChange handler in order to skip the tab change

Environment

  • @blueprintjs/core: 6.1.0
  • Windows 11 24H2
  • Chrome 138

Code Sandbox & Reproduction

  1. Visit https://codesandbox.io/p/sandbox/5fc46c
  2. Right-click the 2nd (inactive) tab
  3. Click the menu item
  4. Observe the active tab change
  5. Repeat with propagation checkbox unticked and observe the defunct ContextMenu

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions