swiper icon indicating copy to clipboard operation
swiper copied to clipboard

anchor <a> tag inside slide snaps to next slide on first click

Open msmzuppa opened this issue 3 years ago • 7 comments

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

msmzuppa avatar Feb 08 '22 15:02 msmzuppa

+1. FF latest. Setting simulateTouch to false does not help.

rawthriver avatar Feb 12 '22 12:02 rawthriver

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

johnozbay avatar Mar 20 '22 10:03 johnozbay

Setting watchSlideProgress to true does not fix it.

msmzuppa avatar Apr 04 '22 10:04 msmzuppa

disabled mousedown on the tags inside the swiper tag

jQuery: $(".swiper").find("a").off("mousedown").on("mousedown", function(e){ e.preventDefault(); e.stopImmediatePropagation(); });

msmzuppa avatar Apr 04 '22 11:04 msmzuppa

jQuery: $(".swiper").find("a").off("mousedown").on("mousedown", function(e){ e.preventDefault(); e.stopImmediatePropagation(); });

thank you! it worked

kwastaras1337 avatar Apr 05 '22 11:04 kwastaras1337

Found the answer here : #3149 (comment) Setting watchSlideProgress to true fixed the problem for our use case.

Also possibly related to #5490

watchSlidesProgress: true solved this problem in my case

ghost avatar May 10 '22 18:05 ghost

Also happens on button tags... Adding e.preventDefault() a your mousedown event (not click) 'fixes' it

AIC-BV avatar Jul 29 '22 13:07 AIC-BV

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.

curtisburns avatar Sep 06 '22 18:09 curtisburns

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

cianmung avatar Dec 16 '22 03:12 cianmung

I had to use pointerdown to make it work:

item.addEventListener('pointerdown', (e) => {
  e.preventDefault()
  e.stopImmediatePropagation()
})

Skoua avatar Nov 10 '23 13:11 Skoua