最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - ReactJS - Disable Click & Hold for Context menu for mobile without disabling click events? - Stack Overflow

programmeradmin0浏览0评论

I'm making a game in ReactJS where I'm using a long press event to perform certain actions in the game (using react-click-n-hold for long press events). When I do these actions on a mobile browser, it always brings up the context menu. How can I disable the context menu on mobile without disabling my click and long press events?

I'm making a game in ReactJS where I'm using a long press event to perform certain actions in the game (using react-click-n-hold for long press events). When I do these actions on a mobile browser, it always brings up the context menu. How can I disable the context menu on mobile without disabling my click and long press events?

Share Improve this question asked May 26, 2020 at 22:22 Patrick JohnsonPatrick Johnson 431 silver badge4 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6
<div onContextMenu={(e)=> e.preventDefault()}... />

This solution from Max Svid worked for me

https://stackoverflow./a/56328162/12722618

Kinda late to the topic I found the holdToDisplay flag of the ContextMenuTrigger element reading the API.
Basically, if you set the flag to -1, the trigger is disabled if you hold the click (set to 1000ms by default).

<ContextMenuTrigger id='menu_id' holdToDisplay={-1}>
  // ...
</ContextMenuTrigger>

Although I admit I haven't tested on mobile browsers.
Hope it helps future readers

发布评论

评论列表(0)

  1. 暂无评论