1
1
import React , { Children , useEffect , useRef , useState } from 'react'
2
- import Box from '../../Box'
3
2
import sx , { SxProp } from '../../sx'
4
3
import { useId , useProvidedRefOrCreate } from '../../hooks'
5
4
import { invariant } from '../../utils/invariant'
@@ -139,6 +138,7 @@ export type TriggerPropsType = {
139
138
onBlur ?: React . FocusEventHandler
140
139
onFocus ?: React . FocusEventHandler
141
140
onMouseEnter ?: React . MouseEventHandler
141
+ onMouseLeave ?: React . MouseEventHandler
142
142
ref ?: React . RefObject < HTMLElement >
143
143
}
144
144
@@ -268,7 +268,7 @@ export const Tooltip = React.forwardRef(
268
268
269
269
return (
270
270
< TooltipContext . Provider value = { { tooltipId} } >
271
- < Box onMouseLeave = { ( ) => closeTooltip ( ) } >
271
+ < >
272
272
{ React . isValidElement ( child ) &&
273
273
React . cloneElement ( child as React . ReactElement < TriggerPropsType > , {
274
274
ref : triggerRef ,
@@ -288,6 +288,10 @@ export const Tooltip = React.forwardRef(
288
288
openTooltip ( )
289
289
child . props . onMouseEnter ?.( event )
290
290
} ,
291
+ onMouseLeave : ( event : React . MouseEvent ) => {
292
+ closeTooltip ( )
293
+ child . props . onMouseLeave ?.( event )
294
+ } ,
291
295
} ) }
292
296
< StyledTooltip
293
297
ref = { tooltipElRef }
@@ -298,10 +302,13 @@ export const Tooltip = React.forwardRef(
298
302
// stop AT from announcing the tooltip twice when it is a label type because it will be announced with "aria-labelledby"
299
303
aria-hidden = { type === 'label' ? true : undefined }
300
304
id = { `tooltip-${ tooltipId } ` }
305
+ // mouse leave and enter on the tooltip itself is needed to keep the tooltip open when the mouse is over the tooltip
306
+ onMouseEnter = { openTooltip }
307
+ onMouseLeave = { closeTooltip }
301
308
>
302
309
{ text }
303
310
</ StyledTooltip >
304
- </ Box >
311
+ </ >
305
312
</ TooltipContext . Provider >
306
313
)
307
314
} ,
0 commit comments