Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions src/components/Tooltip/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ const Tooltip = ({
const tooltipShowDelayTimerRef = useRef<NodeJS.Timeout | null>(null)
const tooltipHideDelayTimerRef = useRef<NodeJS.Timeout | null>(null)
const missedTransitionTimerRef = useRef<NodeJS.Timeout | null>(null)
const tooltipShowTimerRef = useRef<NodeJS.Timeout | null>(null)
const [computedPosition, setComputedPosition] = useState<IComputedPosition>({
tooltipStyles: {},
tooltipArrowStyles: {},
Expand Down Expand Up @@ -194,7 +195,8 @@ const Tooltip = ({
* wait for the component to render and calculate position
* before actually showing
*/
setTimeout(() => {
clearTimeoutRef(tooltipShowTimerRef)
tooltipShowTimerRef.current = setTimeout(() => {
if (!mounted.current) {
return
}
Expand Down Expand Up @@ -348,6 +350,9 @@ const Tooltip = ({
border,
arrowSize,
}).then((computedStylesData) => {
if (!mounted.current) {
return
}
handleComputedPosition(computedStylesData)
})
}
Expand Down Expand Up @@ -759,17 +764,29 @@ const Tooltip = ({
}, [updateTooltipPosition])

useEffect(() => {
if (!contentWrapperRef?.current) {
if (!rendered || !contentWrapperRef?.current) {
return () => null
}
const timeoutIds: Set<NodeJS.Timeout> = new Set()
const contentObserver = new ResizeObserver(() => {
setTimeout(() => updateTooltipPosition())
const timeoutId = setTimeout(() => {
timeoutIds.delete(timeoutId)
if (!mounted.current) {
return
}
updateTooltipPosition()
})
timeoutIds.add(timeoutId)
})
contentObserver.observe(contentWrapperRef.current)
return () => {
contentObserver.disconnect()
timeoutIds.forEach((timeoutId) => {
clearTimeout(timeoutId)
})
timeoutIds.clear()
}
}, [content, contentWrapperRef?.current])
}, [rendered, contentWrapperRef?.current])

useEffect(() => {
const anchorById = document.querySelector<HTMLElement>(`[id='${anchorId}']`)
Expand All @@ -791,6 +808,7 @@ const Tooltip = ({
return () => {
clearTimeoutRef(tooltipShowDelayTimerRef)
clearTimeoutRef(tooltipHideDelayTimerRef)
clearTimeoutRef(tooltipShowTimerRef)
}
}, [])

Expand Down
Loading