Skip to content

Commit

Permalink
updates ToolTip component (after rebase)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimitropoulos committed Jun 4, 2020
1 parent 4f9901d commit 78cb2b1
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/components/tool_tip/tool_tip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,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 } from '../../services';

import { TAB } from '../../services/key_codes';
import { findPopoverPosition, htmlIdGenerator, keys } from '../../services';

import { EuiResizeObserver } from '../observer/resize_observer';

Expand Down Expand Up @@ -243,24 +242,25 @@ export class EuiToolTip extends Component<Props, State> {
window.removeEventListener('mousemove', this.hasFocusMouseMoveListener);
};

onKeyUp = (e: { keyCode: number }) => {
if (e.keyCode === TAB) {
onKeyUp = (event: KeyboardEvent<HTMLSpanElement>) => {
if (event.key === keys.TAB) {
window.addEventListener('mousemove', this.hasFocusMouseMoveListener);
}
};

onMouseOut = (e: ReactMouseEvent<HTMLSpanElement, MouseEvent>) => {
onMouseOut = (event: ReactMouseEvent<HTMLSpanElement, MouseEvent>) => {
// Prevent mousing over children from hiding the tooltip by testing for whether the mouse has
// left the anchor for a non-child.
if (
this.anchor === e.relatedTarget ||
(this.anchor != null && !this.anchor.contains(e.relatedTarget as Node))
this.anchor === event.relatedTarget ||
(this.anchor != null &&
!this.anchor.contains(event.relatedTarget as Node))
) {
this.hideToolTip();
}

if (this.props.onMouseOut) {
this.props.onMouseOut(e);
this.props.onMouseOut(event);
}
};

Expand Down Expand Up @@ -315,7 +315,9 @@ export class EuiToolTip extends Component<Props, State> {
className={anchorClasses}
onMouseOver={this.showToolTip}
onMouseOut={this.onMouseOut}
onKeyUp={e => this.onKeyUp(e)}>
onKeyUp={event => {
this.onKeyUp(event);
}}>
{/**
* Re: jsx-a11y/mouse-events-have-key-events
* We apply onFocus, onBlur, etc to the children element because that's the element
Expand Down

0 comments on commit 78cb2b1

Please sign in to comment.