Skip to content

Commit 40d6de1

Browse files
committed
fix: improve middlewares handling and siableTooltip watcher
1 parent 72de884 commit 40d6de1

2 files changed

Lines changed: 19 additions & 5 deletions

File tree

src/components/Tooltip/Tooltip.tsx

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -718,12 +718,18 @@ const Tooltip = ({
718718
const documentObserverCallback: MutationCallback = (mutationList) => {
719719
const addedAnchors = new Set<HTMLElement>()
720720
const removedAnchors = new Set<HTMLElement>()
721+
const maybeAddAnchor = (anchor: HTMLElement) => {
722+
if (disableTooltip?.(anchor)) {
723+
return
724+
}
725+
addedAnchors.add(anchor)
726+
}
721727
mutationList.forEach((mutation) => {
722728
if (mutation.type === 'attributes' && mutation.attributeName === 'data-tooltip-id') {
723729
const target = mutation.target as HTMLElement
724730
const newId = target.getAttribute('data-tooltip-id')
725731
if (newId === id) {
726-
addedAnchors.add(target)
732+
maybeAddAnchor(target)
727733
} else if (mutation.oldValue === id) {
728734
// data-tooltip-id has now been changed, so we need to remove this anchor
729735
removedAnchors.add(target)
@@ -786,7 +792,7 @@ const Tooltip = ({
786792
const element = node as HTMLElement
787793
if (element.matches(selector)) {
788794
// the element itself is an anchor
789-
addedAnchors.add(element)
795+
maybeAddAnchor(element)
790796
} else {
791797
/**
792798
* TODO(V6): do we care if an element which is an anchor,
@@ -796,7 +802,7 @@ const Tooltip = ({
796802
// the element has children which are anchors
797803
element
798804
.querySelectorAll<HTMLElement>(selector)
799-
.forEach((innerNode) => addedAnchors.add(innerNode))
805+
.forEach((innerNode) => maybeAddAnchor(innerNode))
800806
}
801807
})
802808
} catch {
@@ -832,7 +838,15 @@ const Tooltip = ({
832838
clearTimeoutRef(tooltipHideDelayTimerRef)
833839
clearTimeoutRef(missedTransitionTimerRef)
834840
}
835-
}, [id, anchorSelect, imperativeOptions?.anchorSelect, activeAnchor, handleShow, setActiveAnchor])
841+
}, [
842+
id,
843+
anchorSelect,
844+
imperativeOptions?.anchorSelect,
845+
activeAnchor,
846+
handleShow,
847+
setActiveAnchor,
848+
disableTooltip,
849+
])
836850

837851
useEffect(() => {
838852
updateTooltipPosition()

src/utils/compute-tooltip-position.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const computeTooltipPosition = async ({
2929
return { tooltipStyles: {}, tooltipArrowStyles: {}, place }
3030
}
3131

32-
const middleware = middlewares
32+
const middleware = [...middlewares]
3333

3434
if (tooltipArrowReference) {
3535
middleware.push(arrow({ element: tooltipArrowReference as HTMLElement, padding: 5 }))

0 commit comments

Comments
 (0)