Skip to content

Remove preventDefault() on touchstart and touchmove events#1195

Merged
stepankuzmin merged 2 commits intomapbox:mainfrom
Archetylator:main
Sep 21, 2023
Merged

Remove preventDefault() on touchstart and touchmove events#1195
stepankuzmin merged 2 commits intomapbox:mainfrom
Archetylator:main

Conversation

@Archetylator
Copy link
Contributor

@Archetylator Archetylator commented Aug 17, 2023

Touchstart and touchmove listeners added to the document by default as passive, so that calls to preventDefault will be ignored and will create a browser error like "Unable to preventDefault inside passive event".

The difference between this solution and the previous one tring to fix that bug (5a90472) is that we leave preventDefault inside the touchend event.

More info on: https://chromestatus.com/feature/5093566007214080 and https://developer.mozilla.org/en-US/docs/Web/API/Pointer_events#compatibility_with_mouse_events

Fixes #1019

Touchstart and touchmove listeners added to the document by default as passive,
so that calls to preventDefault will be ignored and will create a browser error like
"Unable to preventDefault inside passive event".

This resolves issues mapbox#1019, mapbox#1054
@stepankuzmin stepankuzmin self-requested a review September 21, 2023 11:21
Copy link
Contributor

@stepankuzmin stepankuzmin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, tested on Safari v17 iOS. Thanks for the contribution, @Archetylator!

@croossin
Copy link

I am unable to get touch events on the map on mobile with these changes. Works for on desktop, but onClick never fired on mobile.

danielsippel added a commit to danielsippel/mapbox-gl-draw that referenced this pull request Apr 17, 2024
danielsippel added a commit to danielsippel/mapbox-gl-draw that referenced this pull request Apr 18, 2024
manuelkasper pushed a commit to manuelkasper/mapbox-gl-draw that referenced this pull request May 27, 2024
* Remove preventDefault() on touchstart and touchmove events

Touchstart and touchmove listeners added to the document by default as passive,
so that calls to preventDefault will be ignored and will create a browser error like
"Unable to preventDefault inside passive event".

This resolves issues mapbox#1019, mapbox#1054

* Revert comment before preventDefault and put it inside touchend
@gillyd12
Copy link

We are also having issues with onclick not being fired on mobile, and would appear the fix for this was reverted?

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

Successfully merging this pull request may close these issues.

Unable to preventDefault inside passive event listener invocation.

4 participants