swiper
swiper copied to clipboard
anchor <a> tag inside slide snaps to next slide on first click
Check that this is really a bug
- [X] I confirm
Reproduction link
https://codesandbox.io/s/elated-margulis-5m21z?file=/index.html
Bug description
when I use a anchor(<a>) tag inside a slide when I do a right click on the tag it slides without animation to the next slide.
Expected Behavior
open browser context menu
Actual Behavior
slides to the next slide without animating
Swiper version
8.0.3
Platform/Target and Browser Versions
Brave 1.34.80 Chromium: 97.0.4692.71
Validations
- [X] Follow our Code of Conduct
- [X] Read the docs.
- [X] Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
- [X] 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
+1. FF latest. Setting simulateTouch to false does not help.
Found the answer here : https://github.com/nolimits4web/Swiper/issues/3149#issuecomment-1044631964
Setting watchSlideProgress
to true
fixed the problem for our use case.
Also possibly related to #5490
Setting watchSlideProgress to true does not fix it.
disabled mousedown on the tags inside the swiper tag
jQuery: $(".swiper").find("a").off("mousedown").on("mousedown", function(e){ e.preventDefault(); e.stopImmediatePropagation(); });
jQuery: $(".swiper").find("a").off("mousedown").on("mousedown", function(e){ e.preventDefault(); e.stopImmediatePropagation(); });
thank you! it worked
Found the answer here : #3149 (comment) Setting
watchSlideProgress
totrue
fixed the problem for our use case.Also possibly related to #5490
watchSlidesProgress: true solved this problem in my case
Also happens on button tags...
Adding e.preventDefault()
a your mousedown event (not click) 'fixes' it
This is still a problem.
Also happens on button tags... Adding
e.preventDefault()
a your mousedown event (not click) 'fixes' it
To build on this, if using React, add via the onMouseDown
prop on the SwiperSlide component.
disabled mousedown on the tags inside the swiper tag
jQuery: $(".swiper").find("a").off("mousedown").on("mousedown", function(e){ e.preventDefault(); e.stopImmediatePropagation(); });
This method works for me! Thank you for the solution :D
I had to use pointerdown
to make it work:
item.addEventListener('pointerdown', (e) => {
e.preventDefault()
e.stopImmediatePropagation()
})