Skip to content

Commit b03247b

Browse files
gabrieljablonskiGabriel Jablonski
authored andcommitted
fix: observe anchor element correctly
1 parent e69ebba commit b03247b

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/components/TooltipController/TooltipController.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,17 +133,19 @@ const TooltipController = ({
133133
return () => null
134134
}
135135

136+
const anchorElement = activeAnchor.current ?? anchorById
137+
136138
const observerCallback: MutationCallback = (mutationList) => {
137139
mutationList.forEach((mutation) => {
138140
if (
139-
!activeAnchor.current ||
141+
!anchorElement ||
140142
mutation.type !== 'attributes' ||
141143
!mutation.attributeName?.startsWith('data-tooltip-')
142144
) {
143145
return
144146
}
145147
// make sure to get all set attributes, since all unset attributes are reset
146-
const dataAttributes = getDataAttributesFromAnchorElement(activeAnchor.current)
148+
const dataAttributes = getDataAttributesFromAnchorElement(anchorElement)
147149
applyAllDataAttributesFromAnchorElement(dataAttributes)
148150
})
149151
}
@@ -155,13 +157,11 @@ const TooltipController = ({
155157
// to stay watching `data-attributes-*` from anchor element
156158
const observerConfig = { attributes: true, childList: false, subtree: false }
157159

158-
const element = activeAnchor.current ?? anchorById
159-
160-
if (element) {
161-
const dataAttributes = getDataAttributesFromAnchorElement(element)
160+
if (anchorElement) {
161+
const dataAttributes = getDataAttributesFromAnchorElement(anchorElement)
162162
applyAllDataAttributesFromAnchorElement(dataAttributes)
163163
// Start observing the target node for configured mutations
164-
observer.observe(element, observerConfig)
164+
observer.observe(anchorElement, observerConfig)
165165
}
166166

167167
return () => {

0 commit comments

Comments
 (0)