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

Swiper Element breaks touch events #6450

Closed
5 of 6 tasks
Paso opened this issue Mar 2, 2023 · 4 comments
Closed
5 of 6 tasks

Swiper Element breaks touch events #6450

Paso opened this issue Mar 2, 2023 · 4 comments

Comments

@Paso
Copy link

Paso commented Mar 2, 2023

Check that this is really a bug

  • I confirm

Reproduction link

https://codepen.io/Tattoo4861/pen/eYLvwjO

Bug description

When using Swiper Element all touch events on the page are broken. Swiper takes over touch and pointer events and re-emits a invalid touchStart event that is missing many expected attributes, such as TouchEvent.touches (see https://developer.mozilla.org/en-US/docs/Web/API/Element/touchstart_event).

In the reproduction codepen we listen to touchStart which should have a touches attribute. When loading swiper the event is missing touches (among other things). If one removes the swiper script-tag the event works as expected again.

The code that is responsible for this is:

  1. swiper.emit('touchStart', e);
  2. el[domMethod]('pointerdown', swiper.onTouchStart, { passive: false });

Swiper should

  1. not create events does not exist, such as touch-events from pointer-events
  2. if emitting a touchStart event make sure it is a valid TouchEvent

Expected Behavior

No response

Actual Behavior

No response

Swiper version

9

Platform/Target and Browser Versions

Win10+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
@nolimits4web nolimits4web closed this as not planned Won't fix, can't repro, duplicate, stale Mar 2, 2023
@Paso
Copy link
Author

Paso commented Mar 2, 2023

Why was it closed? It is clearly a bug that prevents swiper from being used together with other libraries that listens to touch events (such as MUI).

@nolimits4web nolimits4web reopened this Mar 2, 2023
@jvleony
Copy link

jvleony commented Mar 9, 2023

Why was it closed? It is clearly a bug that prevents swiper from being used together with other libraries that listens to touch events (such as MUI).

same issue here, When i click on a MUI button that is embebed inside an slide, y makes a slide navigation.

@tulies
Copy link

tulies commented Mar 14, 2023

Yes, I need to touch events on Android 5. x/6. x。Touch Events is not supported。

@ferhado
Copy link

ferhado commented Sep 24, 2023

I have the same issue.
Adding pointer-events: none; to the elements inside swiper-slide solves the issue but isn't ideal for clickable content:

swiper-slide > * {
  pointer-events: none;
}

Update:

To address the issue while still allowing clickable content, you can add an event listener for touchmove on the Swiper element. Use preventDefault() to handle the touch event and set the passive option to false.

swiperEl.addEventListener("touchmove", (e: Event) => e.preventDefault(), { passive: false });

This approach ensures that Swiper's touch events work as expected, without affecting the functionality of clickable elements within the slides.

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