-
-
Notifications
You must be signed in to change notification settings - Fork 78.8k
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
Fix carousel "hover" behavior on touch-enabled devices #22442
Fix carousel "hover" behavior on touch-enabled devices #22442
Conversation
- touch events are enabled not just on "mobile", just also on touch-enabled desktop/laptop devices; additionally, it's possible to pair a mouse with traditionally touch-only devices (e.g. Android phones/tablets); currently, in these situations the carousel WON'T pause even when using a mouse
This PR does not contain a unit test, as I can't figure out how this new behavior could even be tested...any suggestions welcome... |
as `mouseenter` is fired as part of the touch compatibility events, the previous change results in carousels which cycle until the user tapped/interacted with them. after that they stop cycling (as `mouseleave` is not sent to the carousel after user scrolled/tapped away). this fix resets the cycling after `touchend` - essentially returning to the previous behavior, where on touch the carousel essentially never pauses, but now with the previous fix it at least pauses correctly for mouse users on touch-enabled devices. includes documentation for this new behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, sounds awesome! Sorry I can't review the JS closer—perhaps @Johann-S can weigh in?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
Currently,
mouseenter
/mouseleave
pause the carousel, but these listeners are not added if it's a touch-enabled device. This causes problems on touch-enabled laptop/desktop devices, or when a mouse is paired with, say, an Android phone/tablet, as then the mouse listeners are not added and the carousel does not pause as it should when the user interacts with the mouse.This PR modifies the behavior: mouse listeners are always added. Additionally, on touch devices, an extra
touchend
listener is included. Mouse users on touch-enabled devices now can pause the carousel as expected. If the user interacts with the carousel with the touchscreen, the carousel is now paused for the duration ofthis._config.interval
(plus an extra 500 milliseconds, just to make sure we always wait until the mouse compat events have definitely been fired - which is what made the original code necessary in the first place since touch events also fire amouseenter
compatibility event), and then the cycling is explicitly restarted.This now allows touchscreen users some time to read/interact with the carousel slide, before cycling is resumed. And it fixes the broken behavior for mouse users on touch-enabled devices too.
Closes #20847 (but the problem is not limited to Firefox, same happens on, say, Chrome on a touch-enabled device)