minwork / use-long-press

React hook for detecting click (or tap) and hold event
MIT License
120 stars 12 forks source link

Mobile on Long press, prevent default not working #2

Closed sergeymild closed 3 years ago

sergeymild commented 3 years ago

Hello, i would like make long press on mobile devices and prevent default (it will highlight text and show context menu like copy text of something) and when i'm doing something like this

const longPress = useLongPress((e) => {
    e?.preventDefault()
    e?.stopPropagation()
    e!.cancelable = true
    e!.bubbles = false
    onDelete()
  }, {captureEvent: true});

prevent default doesn't work. it still highlight text and show default context menu

minwork commented 3 years ago

Hello,

have you tried disabling it by css?

  -webkit-user-select: none; /* disable selection/Copy of UIWebView */
  -webkit-touch-callout: none; /* disable the IOS popup when long-press on a link */
minwork commented 3 years ago

I assume that solved your problem and will close that issue for now. Feel free to reopen it if you have any further questions.

rushcodes commented 3 years ago

This problem exists in Firefox Mobile on images - the context menu shows up regardless of whether preventDefault() and all that were called or not.