Description
Check that this is really a bug
- I confirm
Reproduction link
https://codesandbox.io/p/sandbox/swiper-navigation-forked-f7dk5g?file=%2Findex.html%3A65%2C15
Bug description
The preventClick logic is sometimes triggered even when the mouse is perfectly still and no movement occured.
In some cases browsers trigger a pointermove event after a pointerdown event with movementX/Y being 0 and with no movement occuring. Some variants of this bug are documented here and in the duplicate issues:
https://issues.chromium.org/issues/41458793
When preventClick is active, swiperjs will set allowClick to false when a pointermove event occurs after a pointerdown event, regardless of whether the pointer was actually moved. This causes preventDefault to be raised, which for example prevents a form submit from working.
The easiest way to reproduce this behavior is by setting the focus to another window that is not the browser and then directly clicking on the link or button in the swiper provided in the sandbox above. You will notice that when the focus is on the browser from the beginning, the button will work and open a new tab. When the focus was outside the browser, the click will be prevented.
In my own project I encountered other scenarios where these 0 movement events occur, but they are less easy to reproduce.
While I realize that this bug should be fixed by the browser, the bug is several years old, so there is little hope that this will happen soon.
My suggestion for a fix would be to check for movementX/Y being greater than zero before preventing any clicks. I would be happy to contribute a PR if that fix seems reasonable to you.
Expected Behavior
Clicking the button in the slide in the playground will open a new tab if the mouse was not moved during the click.
Actual Behavior
The click is sometimes ignored. For example, when the focus is outside the browser when clicking.
Swiper version
11.2.10
Platform/Target and Browser Versions
Chrome
Validations
- Follow our Code of Conduct
- Read the docs.
- Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
- Make sure this is a Swiper issue and not a framework-specific issue
Would you like to open a PR for this bug?
- I'm willing to open a PR