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

Workaround for iOS hover events bug #815

Merged
merged 1 commit into from Jul 22, 2020
Merged

Workaround for iOS hover events bug #815

merged 1 commit into from Jul 22, 2020

Conversation

devongovett
Copy link
Member

This works around a bug in iOS Safari that fires the onPointerEnter and onMouseEnter between the onPointerUp and onFocus events. This caused onPointerEnter to be fired twice: once on touch and once before focus, which meant that useHover fired a hover event even though you're on a touch device. Webkit bug filed here: https://bugs.webkit.org/show_bug.cgi?id=214609.

The workaround is to register a global event listener for the pointerup/touched event, which sets a flag and unsets it after a quick timeout (after the onFocus event). This handles two scenarios: the iOS case where onPointerEnter is fired prior to focus, and the non-iOS case where this event is not fired. In that case, we do not want to leave the flag hanging, because if the user switched to a mouse after touching the element, the hover event would not fire. The short delay to reset this fixes that.

The event is global due to another iOS quirk: focus events (and the prior onPointerEnter) are dispatched even when you didn't touch directly on the element, but somewhere nearby. iOS seems to be doing some magic to move focus to the closest element. This means we cannot use a touch event handler on the element itself to determine if there's a preceding touch, we need to listen on the document instead.


export interface HoverProps extends HoverEvents {
/** Whether the hover events should be disabled. */
isDisabled?: boolean,
isHovered?: boolean
Copy link
Member Author

Choose a reason for hiding this comment

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

Removed this since the prop didn't seem to be used anywhere. Was added in #775. We can add back later if needed.

@adobe-bot
Copy link

Build successful! 🎉

@dannify dannify merged commit 452d1cb into main Jul 22, 2020
@dannify dannify deleted the ios-hover-bug branch July 22, 2020 17:16
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.

None yet

3 participants