Skip to content

Commit 555c133

Browse files
fix: improve click outside check performance
1 parent b2160bc commit 555c133

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/components/Tooltip/Tooltip.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,12 +282,13 @@ const Tooltip = ({
282282
if (!show) {
283283
return
284284
}
285-
const anchorById = document.querySelector<HTMLElement>(`[id='${anchorId}']`)
286-
const anchors = [anchorById, ...anchorsBySelect]
287-
if (anchors.some((anchor) => anchor?.contains(event.target as HTMLElement))) {
285+
const target = event.target as HTMLElement
286+
if (tooltipRef.current?.contains(target)) {
288287
return
289288
}
290-
if (tooltipRef.current?.contains(event.target as HTMLElement)) {
289+
const anchorById = document.querySelector<HTMLElement>(`[id='${anchorId}']`)
290+
const anchors = [anchorById, ...anchorsBySelect]
291+
if (anchors.some((anchor) => anchor?.contains(target))) {
291292
return
292293
}
293294
handleShow(false)

0 commit comments

Comments
 (0)