@@ -3,6 +3,7 @@ import classNames from 'classnames'
33import debounce from 'utils/debounce'
44import { useTooltip } from 'components/TooltipProvider'
55import useIsomorphicLayoutEffect from 'utils/use-isomorphic-layout-effect'
6+ import { autoUpdate } from '@floating-ui/dom'
67import { getScrollParent } from 'utils/get-scroll-parent'
78import { computeTooltipPosition } from 'utils/compute-positions'
89import coreStyles from './core-styles.module.css'
@@ -335,7 +336,6 @@ const Tooltip = ({
335336 setActualPlacement ( computedStylesData . place as PlacesType )
336337 } )
337338 }
338- const debouncedUpdateTooltipPosition = debounce ( updateTooltipPosition , 100 , true )
339339
340340 useEffect ( ( ) => {
341341 const elementRefs = new Set ( anchorRefs )
@@ -361,10 +361,20 @@ const Tooltip = ({
361361 anchorScrollParent ?. addEventListener ( 'scroll' , handleScrollResize )
362362 tooltipScrollParent ?. addEventListener ( 'scroll' , handleScrollResize )
363363 }
364+ let updateTooltipCleanup : null | ( ( ) => void ) = null
364365 if ( closeOnResize ) {
365366 window . addEventListener ( 'resize' , handleScrollResize )
366- } else {
367- window . addEventListener ( 'resize' , debouncedUpdateTooltipPosition )
367+ } else if ( activeAnchor && tooltipRef . current ) {
368+ updateTooltipCleanup = autoUpdate (
369+ activeAnchor as HTMLElement ,
370+ tooltipRef . current as HTMLElement ,
371+ updateTooltipPosition ,
372+ {
373+ ancestorResize : true ,
374+ elementResize : true ,
375+ layoutShift : true ,
376+ } ,
377+ )
368378 }
369379
370380 const handleEsc = ( event : KeyboardEvent ) => {
@@ -426,7 +436,7 @@ const Tooltip = ({
426436 if ( closeOnResize ) {
427437 window . removeEventListener ( 'resize' , handleScrollResize )
428438 } else {
429- window . removeEventListener ( 'resize' , debouncedUpdateTooltipPosition )
439+ updateTooltipCleanup ?. ( )
430440 }
431441 if ( shouldOpenOnClick ) {
432442 window . removeEventListener ( 'click' , handleClickOutsideAnchors )
0 commit comments