Skip to content

Commit 35dc340

Browse files
fix: check if target is in DOM before showing
1 parent 4c90dbb commit 35dc340

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/components/Tooltip/Tooltip.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,23 @@ const Tooltip = ({
171171
if (!event) {
172172
return
173173
}
174+
const target = (event.currentTarget ?? event.target) as HTMLElement | null
175+
if (!target?.isConnected) {
176+
/**
177+
* this happens when the target is removed from the DOM
178+
* at the same time the tooltip gets triggered
179+
*/
180+
setActiveAnchor(null)
181+
setProviderActiveAnchor({ current: null })
182+
return
183+
}
174184
if (delayShow) {
175185
handleShowTooltipDelayed()
176186
} else {
177187
handleShow(true)
178188
}
179-
const target = event.currentTarget ?? event.target
180-
setActiveAnchor(target as HTMLElement)
181-
setProviderActiveAnchor({ current: target as HTMLElement })
189+
setActiveAnchor(target)
190+
setProviderActiveAnchor({ current: target })
182191

183192
if (tooltipHideDelayTimerRef.current) {
184193
clearTimeout(tooltipHideDelayTimerRef.current)

0 commit comments

Comments
 (0)