From 90909251b4fca3087a79f8142fc768d3f45d5543 Mon Sep 17 00:00:00 2001 From: cchaos Date: Thu, 19 Aug 2021 18:44:19 -0400 Subject: [PATCH] Revert "Remove tooltip focus on mousemove (#3335)" This reverts commit fd3dd846d9a9c505d39ce873ef6f49e6cd738097. # Conflicts: # CHANGELOG.md # src/components/tool_tip/tool_tip.tsx --- .../__snapshots__/code_block.test.tsx.snap | 1 - src/components/tool_tip/tool_tip.tsx | 32 ++++++++++--------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/components/code/__snapshots__/code_block.test.tsx.snap b/src/components/code/__snapshots__/code_block.test.tsx.snap index d4b78843b9b..1dcdc1486cf 100644 --- a/src/components/code/__snapshots__/code_block.test.tsx.snap +++ b/src/components/code/__snapshots__/code_block.test.tsx.snap @@ -185,7 +185,6 @@ console.log(some);" > diff --git a/src/components/tool_tip/tool_tip.tsx b/src/components/tool_tip/tool_tip.tsx index 6e590f5bf93..a69fbabc343 100644 --- a/src/components/tool_tip/tool_tip.tsx +++ b/src/components/tool_tip/tool_tip.tsx @@ -13,15 +13,14 @@ import React, { ReactElement, ReactNode, MouseEvent as ReactMouseEvent, - KeyboardEvent, } from 'react'; import classNames from 'classnames'; import { keysOf } from '../common'; import { EuiPortal } from '../portal'; import { EuiToolTipPopover } from './tool_tip_popover'; -import { findPopoverPosition, htmlIdGenerator, keys } from '../../services'; import { enqueueStateChange } from '../../services/react'; +import { findPopoverPosition, htmlIdGenerator } from '../../services'; import { EuiResizeObserver } from '../observer/resize_observer'; @@ -116,6 +115,7 @@ export interface EuiToolTipProps { interface State { visible: boolean; + hasFocus: boolean; calculatedPosition: ToolTipPositions; toolTipStyles: ToolTipStyles; arrowStyles: undefined | { left: number; top: number }; @@ -130,6 +130,7 @@ export class EuiToolTip extends Component { state: State = { visible: false, + hasFocus: false, calculatedPosition: this.props.position, toolTipStyles: DEFAULT_TOOLTIP_STYLES, arrowStyles: undefined, @@ -154,7 +155,6 @@ export class EuiToolTip extends Component { componentWillUnmount() { this.clearAnimationTimeout(); this._isMounted = false; - window.removeEventListener('mousemove', this.hasFocusMouseMoveListener); } componentDidUpdate(prevProps: EuiToolTipProps, prevState: State) { @@ -252,15 +252,18 @@ export class EuiToolTip extends Component { }); }; - hasFocusMouseMoveListener = () => { - this.hideToolTip(); - window.removeEventListener('mousemove', this.hasFocusMouseMoveListener); + onFocus = () => { + this.setState({ + hasFocus: true, + }); + this.showToolTip(); }; - onKeyUp = (event: KeyboardEvent) => { - if (event.key === keys.TAB) { - window.addEventListener('mousemove', this.hasFocusMouseMoveListener); - } + onBlur = () => { + this.setState({ + hasFocus: false, + }); + this.hideToolTip(); }; onMouseOut = (event: ReactMouseEvent) => { @@ -271,7 +274,9 @@ export class EuiToolTip extends Component { (this.anchor != null && !this.anchor.contains(event.relatedTarget as Node)) ) { - this.hideToolTip(); + if (!this.state.hasFocus) { + this.hideToolTip(); + } } if (this.props.onMouseOut) { @@ -333,10 +338,7 @@ export class EuiToolTip extends Component { ref={(anchor) => (this.anchor = anchor)} className={anchorClasses} onMouseOver={this.showToolTip} - onMouseOut={this.onMouseOut} - onKeyUp={(event) => { - this.onKeyUp(event); - }}> + onMouseOut={this.onMouseOut}> {/** * Re: jsx-a11y/mouse-events-have-key-events * We apply onFocus, onBlur, etc to the children element because that's the element