react-draggable icon indicating copy to clipboard operation
react-draggable copied to clipboard

Not possible to listen to click events inside a `Draggable` on Mobile

Open ChristophP opened this issue 2 years ago • 7 comments

Hi,

we are using react-draggable and have a link inside a draggable which should be clickable.

 <Draggable
        axis="x"
        >
        <Link>I should be clickable</Link>
  </Draggable>

On a non-touch device this works fine as the click event fires normally. However, on touch devices the click event is not fired at all, which is unfortunate. The line of code responsible for this, seems to be this one:

https://github.com/react-grid-layout/react-draggable/blob/44a8c6ed103ec6c0a4dda5faf7f8ebca16f9b325/lib/DraggableCore.js#L295

touchstart event are cancelled there, resulting in the click never firing.

Since this line seems to be in place to prevent scrolling on touch devices, would a possible solution be to cancel touchmove instead?

Another solution may be to cancel the touchstart event higher up

ChristophP avatar Aug 07 '23 05:08 ChristophP

I have the same problem.

darya425 avatar Aug 17 '23 19:08 darya425

I have the same problem too.

Jeff-Bee avatar Aug 21 '23 09:08 Jeff-Bee

@quolpr Hi, can you help us?

darya425 avatar Aug 22 '23 21:08 darya425

This solution might help with this problem [JeanNicolasdeLamballerie](https://github.com/react-grid-layout/react-draggable/issues/666#issuecomment-1425663673) I tried it and I got the links to work on mobile

relense avatar Aug 29 '23 17:08 relense

I have the same problem too.

But now it working for me image

add cancel props in the Draggable component like cancel={'.need-interaction'}

Nav Component image

add that className to each Link component

NadirBakhsh avatar Sep 15 '23 09:09 NadirBakhsh

@NadirBakhsh oh that seems like a nice solution. Will need to try.

ChristophP avatar Sep 15 '23 10:09 ChristophP

The .cancel property works for me. Thanks.

ChristophP avatar Nov 04 '23 13:11 ChristophP

@STRML could we at the very least get a way to disable the line that is causing this issue:

    // Prevent scrolling on mobile devices, like ipad/iphone.
    // Important that this is after handle/cancel.
    if (e.type === 'touchstart') e.preventDefault();

for my use case I don't need to prevent scrolling on a mobile device but DO need clicks to work inside the draggable component!

Thanks!

tnrich avatar Aug 08 '24 18:08 tnrich

I'm happy to review a PR on this.

STRML avatar Aug 08 '24 19:08 STRML

@STRML PR here - https://github.com/react-grid-layout/react-draggable/pull/760

Thanks!

tnrich avatar Aug 08 '24 19:08 tnrich