From b41ecc9f0609287d16fc1bbf5b1f8f2b1930574a Mon Sep 17 00:00:00 2001 From: gabrieljablonski Date: Mon, 7 Apr 2025 18:45:59 -0300 Subject: [PATCH] fix: handle clicking nested anchor elements --- src/components/Tooltip/Tooltip.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/components/Tooltip/Tooltip.tsx b/src/components/Tooltip/Tooltip.tsx index 1471e930..832f79cf 100644 --- a/src/components/Tooltip/Tooltip.tsx +++ b/src/components/Tooltip/Tooltip.tsx @@ -515,8 +515,10 @@ const Tooltip = ({ const enabledEvents: { event: string; listener: (event?: Event) => void }[] = [] + const activeAnchorContainsTarget = (event?: Event): boolean => + Boolean(event?.target && activeAnchor?.contains(event.target as HTMLElement)) const handleClickOpenTooltipAnchor = (event?: Event) => { - if (show && event?.target === activeAnchor) { + if (show && activeAnchorContainsTarget(event)) { /** * ignore clicking the anchor that was used to open the tooltip. * this avoids conflict with the click close event. @@ -526,7 +528,7 @@ const Tooltip = ({ handleShowTooltip(event) } const handleClickCloseTooltipAnchor = (event?: Event) => { - if (!show || event?.target !== activeAnchor) { + if (!show || !activeAnchorContainsTarget(event)) { /** * ignore clicking the anchor that was NOT used to open the tooltip. * this avoids closing the tooltip when clicking on a