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

fixed tooltip shows up on Mobile Web while navigating the reports #2044

Merged
merged 2 commits into from
Mar 24, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/components/Hoverable/index.js
Original file line number Diff line number Diff line change
@@ -22,10 +22,25 @@ class Hoverable extends Component {

componentDidMount() {
document.addEventListener('mousedown', this.resetHoverStateOnOutsideClick);

// we like to Block the hover on touch devices but we keep it for Hybrid devices so
// following logic blocks hover on touch devices.
this.disableHover = () => {
this.hoverDisabled = true;
};
this.enableHover = () => {
this.hoverDisabled = false;
};
document.addEventListener('touchstart', this.disableHover);

// Remember Touchend fires before `mouse` events so we have to use alternative.
document.addEventListener('touchmove', this.enableHover);
}

componentWillUnmount() {
document.removeEventListener('mousedown', this.resetHoverStateOnOutsideClick);
document.removeEventListener('touchstart', this.disableHover);
document.removeEventListener('touchmove', this.enableHover);
}

/**
@@ -34,9 +49,14 @@ class Hoverable extends Component {
* @param {Boolean} isHovered - Whether or not this component is hovered.
*/
setIsHovered(isHovered) {
if (isHovered !== this.state.isHovered) {
if (isHovered !== this.state.isHovered && !(isHovered && this.hoverDisabled)) {
this.setState({isHovered}, isHovered ? this.props.onHoverIn : this.props.onHoverOut);
}

// we reset the Hover block in case touchmove was not first after touctstart
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you help me understand the race condition that can occur here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it is possible that the touchmove never fires.

if (!isHovered) {
this.hoverDisabled = false;
}
}

/**