From 5c563574e8e334edfe7c23eabf621fe33de9eaae Mon Sep 17 00:00:00 2001 From: Mikhail Rychagov Date: Thu, 18 Jan 2024 19:29:55 +0700 Subject: [PATCH] Remove anchor when data-tooltip-id gets changed --- src/components/Tooltip/Tooltip.tsx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/components/Tooltip/Tooltip.tsx b/src/components/Tooltip/Tooltip.tsx index 280da9f8..b60ab20c 100644 --- a/src/components/Tooltip/Tooltip.tsx +++ b/src/components/Tooltip/Tooltip.tsx @@ -643,6 +643,9 @@ const Tooltip = ({ const newId = (mutation.target as HTMLElement).getAttribute('data-tooltip-id') if (newId === id) { newAnchors.push(mutation.target as HTMLElement) + } else if (mutation.oldValue === id) { + // data-tooltip-id has now been changed, so we need to remove this anchor + removedAnchors.push(mutation.target as HTMLElement) } } if (mutation.type !== 'childList') { @@ -727,6 +730,8 @@ const Tooltip = ({ subtree: true, attributes: true, attributeFilter: ['data-tooltip-id'], + // to track the prev value if we need to remove anchor when data-tooltip-id gets changed + attributeOldValue: true, }) return () => { documentObserver.disconnect()