From 1ad111ac81840e8a19873b1e2d3e3b79048651de Mon Sep 17 00:00:00 2001 From: gabrieljablonski Date: Wed, 20 Dec 2023 18:44:04 -0300 Subject: [PATCH 1/2] fix: click events behavior --- src/components/Tooltip/Tooltip.tsx | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/components/Tooltip/Tooltip.tsx b/src/components/Tooltip/Tooltip.tsx index 3f3b8641..648e0cda 100644 --- a/src/components/Tooltip/Tooltip.tsx +++ b/src/components/Tooltip/Tooltip.tsx @@ -477,13 +477,20 @@ const Tooltip = ({ const enabledEvents: { event: string; listener: (event?: Event) => void }[] = [] const handleClickOpenTooltipAnchor = (event?: Event) => { - if (show) { + if (show && event?.target === activeAnchor) { + /** + * ignore clicking the anchor that was used to open the tooltip. + * this avoids conflict with the click close event. + */ return } handleShowTooltip(event) } - const handleClickCloseTooltipAnchor = () => { - if (!show) { + const handleClickCloseTooltipAnchor = (event?: Event) => { + if (!show || event?.target !== activeAnchor) { + /** + * same reasoning as above, opposite logic. + */ return } handleHideTooltip() From 532640a47231779e526a8a1bff5159cbd7e6de1e Mon Sep 17 00:00:00 2001 From: Gabriel Jablonski Date: Wed, 27 Dec 2023 11:30:01 -0300 Subject: [PATCH 2/2] docs: update source comments --- src/components/Tooltip/Tooltip.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/Tooltip/Tooltip.tsx b/src/components/Tooltip/Tooltip.tsx index 648e0cda..396f574c 100644 --- a/src/components/Tooltip/Tooltip.tsx +++ b/src/components/Tooltip/Tooltip.tsx @@ -489,7 +489,8 @@ const Tooltip = ({ const handleClickCloseTooltipAnchor = (event?: Event) => { if (!show || event?.target !== activeAnchor) { /** - * same reasoning as above, opposite logic. + * ignore clicking the anchor that was NOT used to open the tooltip. + * this avoids closing the tooltip when clicking on a new anchor with the tooltip already open. */ return }