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

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

Closed
5 of 6 tasks
msmzuppa opened this issue Feb 8, 2022 · 10 comments
Closed
5 of 6 tasks

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

msmzuppa opened this issue Feb 8, 2022 · 10 comments

Comments

@msmzuppa
Copy link

msmzuppa commented Feb 8, 2022

Check that this is really a bug

  • 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

  • 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
@rawthriver
Copy link

rawthriver commented Feb 12, 2022

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

@johnozbay
Copy link

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


Also possibly related to #5490

@msmzuppa
Copy link
Author

msmzuppa commented Apr 4, 2022

Setting watchSlideProgress to true does not fix it.

@msmzuppa msmzuppa changed the title anchor <a> tag inside slide snaps to next slide on right click anchor <a> tag inside slide snaps to next slide on first click Apr 4, 2022
@msmzuppa
Copy link
Author

msmzuppa commented Apr 4, 2022

disabled mousedown on the tags inside the swiper tag

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

@kwastaras1337
Copy link

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

thank you! it worked

@ghost
Copy link

ghost commented May 10, 2022

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

@AIC-BV
Copy link

AIC-BV commented Jul 29, 2022

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

@curtisburns
Copy link

curtisburns commented Sep 6, 2022

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.

@cianmung
Copy link

cianmung commented Dec 16, 2022

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

@Skoua
Copy link

Skoua commented Nov 10, 2023

I had to use pointerdown to make it work:

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

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

8 participants