Skip to content

Commit d4e1eb7

Browse files
committed
fix(TooltipV2): delay tooltip opening time by ms
1 parent 00da88a commit d4e1eb7

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

packages/react/src/TooltipV2/Tooltip.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@ export const Tooltip = React.forwardRef(
213213

214214
const [isPopoverOpen, setIsPopoverOpen] = useState(false)
215215

216+
const [timeoutId, setTimeoutId] = useState<NodeJS.Timeout | null>(null)
217+
216218
const openTooltip = () => {
217219
try {
218220
if (
@@ -362,10 +364,19 @@ export const Tooltip = React.forwardRef(
362364
child.props.onFocus?.(event)
363365
},
364366
onMouseEnter: (event: React.MouseEvent) => {
365-
openTooltip()
366-
child.props.onMouseEnter?.(event)
367+
// show tooltip after mosue has been hovering for at least 50ms
368+
// (prevent showing tooltip when mouse is just passing through)
369+
const timeoutId = setTimeout(() => {
370+
openTooltip()
371+
child.props.onMouseEnter?.(event)
372+
}, 50)
373+
374+
setTimeoutId(timeoutId)
367375
},
368376
onMouseLeave: (event: React.MouseEvent) => {
377+
if (timeoutId) {
378+
clearTimeout(timeoutId)
379+
}
369380
closeTooltip()
370381
child.props.onMouseLeave?.(event)
371382
},

0 commit comments

Comments
 (0)