Skip to content

Commit b41ecc9

Browse files
fix: handle clicking nested anchor elements
1 parent 9cc0685 commit b41ecc9

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Diff for: src/components/Tooltip/Tooltip.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -515,8 +515,10 @@ const Tooltip = ({
515515

516516
const enabledEvents: { event: string; listener: (event?: Event) => void }[] = []
517517

518+
const activeAnchorContainsTarget = (event?: Event): boolean =>
519+
Boolean(event?.target && activeAnchor?.contains(event.target as HTMLElement))
518520
const handleClickOpenTooltipAnchor = (event?: Event) => {
519-
if (show && event?.target === activeAnchor) {
521+
if (show && activeAnchorContainsTarget(event)) {
520522
/**
521523
* ignore clicking the anchor that was used to open the tooltip.
522524
* this avoids conflict with the click close event.
@@ -526,7 +528,7 @@ const Tooltip = ({
526528
handleShowTooltip(event)
527529
}
528530
const handleClickCloseTooltipAnchor = (event?: Event) => {
529-
if (!show || event?.target !== activeAnchor) {
531+
if (!show || !activeAnchorContainsTarget(event)) {
530532
/**
531533
* ignore clicking the anchor that was NOT used to open the tooltip.
532534
* this avoids closing the tooltip when clicking on a

0 commit comments

Comments
 (0)