@@ -58,6 +58,7 @@ interface ToolTipStyles {
5858 right ?: number | 'auto' ;
5959 opacity ?: number ;
6060 visibility ?: 'hidden' ;
61+ animation ?: 'none' ;
6162}
6263
6364const DEFAULT_TOOLTIP_STYLES : ToolTipStyles = {
@@ -173,6 +174,7 @@ export const EuiToolTip = forwardRef<EuiToolTipRef, EuiToolTipProps>(
173174 const componentDefaultsContext = useContext ( EuiComponentDefaultsContext ) ;
174175
175176 const [ visible , setVisible ] = useState ( false ) ;
177+ const [ skipAnimation , setSkipAnimation ] = useState ( false ) ;
176178 const [ hasFocus , setHasFocus ] = useState ( false ) ;
177179 const [ calculatedPosition , setCalculatedPosition ] =
178180 useState < ToolTipPositions > ( positionProp ) ;
@@ -247,10 +249,20 @@ export const EuiToolTip = forwardRef<EuiToolTipRef, EuiToolTipProps>(
247249 toolTipManager . deregisterToolTip ( hideToolTip ) ;
248250 } , [ ] ) ;
249251
252+ /**
253+ * Show the tooltip.
254+ *
255+ * Uses the tooltip manager's `skipAnimation` signal to optionally skip the entry
256+ * animation when another tooltip is already open or was just closed.
257+ */
250258 const showToolTip = useCallback ( ( ) => {
251259 if ( ! content && ! title ) return ;
260+
261+ const result = toolTipManager . registerTooltip ( hideToolTip ) ;
262+ if ( ! result ) return ;
263+
264+ setSkipAnimation ( result . skipAnimation ) ;
252265 setVisible ( true ) ;
253- toolTipManager . registerTooltip ( hideToolTip ) ;
254266 } , [ content , title , hideToolTip ] ) ;
255267
256268 useImperativeHandle ( ref , ( ) => ( { showToolTip, hideToolTip, id } ) , [
@@ -351,25 +363,26 @@ export const EuiToolTip = forwardRef<EuiToolTipRef, EuiToolTipProps>(
351363 [ disableScreenReaderOutput , visible , hideToolTip ]
352364 ) ;
353365
354- const onMouseOut = useCallback (
366+ /**
367+ * Show the tooltip on enter.
368+ */
369+ const onMouseEnter = useCallback (
355370 ( event : ReactMouseEvent < HTMLSpanElement , MouseEvent > ) => {
356- // Prevent mousing over children from hiding the tooltip by testing for whether the mouse has
357- // left the anchor for a non-child.
358- if (
359- anchorRef . current === event . relatedTarget ||
360- ( anchorRef . current != null &&
361- ! anchorRef . current . contains ( event . relatedTarget as Node ) )
362- ) {
363- if ( ! hasFocus ) {
364- hideToolTip ( ) ;
365- }
366- }
371+ showToolTip ( ) ;
372+ anchorProps ?. onMouseEnter ?.( event ) ;
373+ } ,
374+ [ showToolTip , anchorProps ?. onMouseEnter ]
375+ ) ;
367376
368- if ( onMouseOutProp ) {
369- onMouseOutProp ( event ) ;
370- }
377+ /**
378+ * Hide the tooltip if the mouse is not over the trigger.
379+ */
380+ const onMouseLeave = useCallback (
381+ ( event : ReactMouseEvent < HTMLSpanElement , MouseEvent > ) => {
382+ if ( ! hasFocus ) hideToolTip ( ) ;
383+ anchorProps ?. onMouseLeave ?.( event ) ;
371384 } ,
372- [ hasFocus , hideToolTip , onMouseOutProp ]
385+ [ hasFocus , hideToolTip , anchorProps ?. onMouseLeave ]
373386 ) ;
374387
375388 const classes = classNames ( 'euiToolTip' , className ) ;
@@ -383,8 +396,9 @@ export const EuiToolTip = forwardRef<EuiToolTipRef, EuiToolTipProps>(
383396 onBlur = { onBlur }
384397 onFocus = { onFocus }
385398 onKeyDown = { onEscapeKey }
386- onMouseOver = { showToolTip }
387- onMouseOut = { onMouseOut }
399+ onMouseEnter = { onMouseEnter }
400+ onMouseLeave = { onMouseLeave }
401+ onMouseOut = { onMouseOutProp }
388402 // `id` defines if the trigger and tooltip are automatically linked via `aria-describedby`.
389403 id = { ! disableScreenReaderOutput ? id : undefined }
390404 className = { anchorClasses }
@@ -397,7 +411,13 @@ export const EuiToolTip = forwardRef<EuiToolTipRef, EuiToolTipProps>(
397411 < EuiPortal >
398412 < EuiToolTipPopover
399413 className = { classes }
400- style = { toolTipStyles }
414+ style = { {
415+ ...toolTipStyles ,
416+ // Inline `animation: none` overrides the keyframes fade-in
417+ // shorthand on the base `.euiToolTip` class, so a tooltip
418+ // shown right after another closes appears instantly.
419+ animation : skipAnimation ? 'none' : undefined ,
420+ } }
401421 positionToolTip = { positionToolTip }
402422 popoverRef = { setPopoverRef }
403423 title = { title }
0 commit comments