palantir/blueprint

ContextMenuPopover browser context menu occasionally appears

开放

#6,469 创建于 2023年10月17日

 (4 条评论) (0 个反应) (0 位负责人)TypeScript (2,167 个派生)batch import
P3Package: coreType: bughelp wanted

仓库指标

星标
 (20,263 个星标)
PR 合并指标
 (平均合并 43天 10小时) (30 天内合并 27 个 PR)

描述

Environment

  • @blueprintjs/core@: 5.5.1
  • react: 17.0.2
  • Windows 10
  • Chrome 118.0.5993.71

Code Sandbox

https://blueprintjs.com/docs/#core/components/context-menu-popover.imperative-api

Steps to reproduce

This issue was previously reported as #6005. That was closed as resolved but the problem is still occurring. It's difficult to get it to happen in the documentation site but in a project that uses Blueprint.js it can be 1 in 3 right clicks will display the browser context menu.

The following code will log <div class="bp5-overlay-backdrop bp5-popover-backdrop bp5-context-menu-backdrop bp5-popover-appear-done bp5-popover-enter-done"></div> on a right click that triggers the browser context menu.

window.addEventListener('contextmenu', (e) => { console.log(e.target); });

Actual behavior

Recording-20231017_104614.webm

Expected behavior

Browser context menu is suppressed successfully. Repeating the same steps on ContextMenu does not show the browser's context menu.

Possible solution

There may be a short moment in time that the right click is propagated to the newly added overlay, before the overlay has its event set up to close the new ContextPopoverMenu on right click.

  1. Right click launches ContextMenu2 and calls preventDefault()
  2. Overlay is added quickly
  3. Right click propagates to overlay
  4. Right click menu appears <-- Problem might be here
  5. Overlay adds event to dismiss itself on any click event

贡献者指南