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

Open
ChristophP opened this issue Aug 7, 2023 · 7 comments
Open

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.

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

No branches or pull requests

5 participants