Skip to content

Commit 6d2a880

Browse files
mixrichgabrieljablonski
authored andcommitted
Remove anchor when data-tooltip-id gets changed
1 parent 0b395a4 commit 6d2a880

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

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

+5
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,9 @@ const Tooltip = ({
643643
const newId = (mutation.target as HTMLElement).getAttribute('data-tooltip-id')
644644
if (newId === id) {
645645
newAnchors.push(mutation.target as HTMLElement)
646+
} else if (mutation.oldValue === id) {
647+
// data-tooltip-id has now been changed, so we need to remove this anchor
648+
removedAnchors.push(mutation.target as HTMLElement)
646649
}
647650
}
648651
if (mutation.type !== 'childList') {
@@ -727,6 +730,8 @@ const Tooltip = ({
727730
subtree: true,
728731
attributes: true,
729732
attributeFilter: ['data-tooltip-id'],
733+
// to track the prev value if we need to remove anchor when data-tooltip-id gets changed
734+
attributeOldValue: true,
730735
})
731736
return () => {
732737
documentObserver.disconnect()

0 commit comments

Comments
 (0)