Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not possible to listen to click events inside a Draggable on Mobile #728

Closed
ChristophP opened this issue Aug 7, 2023 · 10 comments · Fixed by #760
Closed

Not possible to listen to click events inside a Draggable on Mobile #728

ChristophP opened this issue Aug 7, 2023 · 10 comments · Fixed by #760

Comments

@ChristophP
Copy link

ChristophP commented Aug 7, 2023

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:

if (e.type === 'touchstart') e.preventDefault();

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 ChristophP changed the title Not possinle to listen to click events inside a Draggable on Mobile Not possible to listen to click events inside a Draggable on Mobile Aug 7, 2023
@darya425
Copy link

I have the same problem.

@Jeff-Bee
Copy link

I have the same problem too.

@darya425
Copy link

@quolpr Hi, can you help us?

@relense
Copy link

relense commented Aug 29, 2023

This solution might help with this problem [JeanNicolasdeLamballerie](#666 (comment)) I tried it and I got the links to work on mobile

@NadirBakhsh
Copy link

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

@ChristophP
Copy link
Author

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

@ChristophP
Copy link
Author

The .cancel property works for me. Thanks.

@tnrich
Copy link
Contributor

tnrich commented Aug 8, 2024

@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!

@STRML
Copy link
Collaborator

STRML commented Aug 8, 2024

I'm happy to review a PR on this.

@tnrich
Copy link
Contributor

tnrich commented Aug 8, 2024

@STRML PR here - #760

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
7 participants