diff --git a/.yarn/versions/1d095e39.yml b/.yarn/versions/1d095e39.yml new file mode 100644 index 0000000000..12216f5978 --- /dev/null +++ b/.yarn/versions/1d095e39.yml @@ -0,0 +1,5 @@ +releases: + "@radix-ui/react-tooltip": patch + +declined: + - primitives \ No newline at end of file diff --git a/packages/react/tooltip/src/Tooltip.tsx b/packages/react/tooltip/src/Tooltip.tsx index 269cfd32f2..094695d2fb 100644 --- a/packages/react/tooltip/src/Tooltip.tsx +++ b/packages/react/tooltip/src/Tooltip.tsx @@ -30,7 +30,7 @@ const DEFAULT_DELAY_DURATION = 700; const TOOLTIP_OPEN = 'tooltip.open'; type TooltipProviderContextValue = { - isOpenDelayed: boolean; + isOpenDelayedRef: React.MutableRefObject; delayDuration: number; onOpen(): void; onClose(): void; @@ -71,7 +71,7 @@ const TooltipProvider: React.FC = ( disableHoverableContent = false, children, } = props; - const [isOpenDelayed, setIsOpenDelayed] = React.useState(true); + const isOpenDelayedRef = React.useRef(true); const isPointerInTransitRef = React.useRef(false); const skipDelayTimerRef = React.useRef(0); @@ -83,16 +83,16 @@ const TooltipProvider: React.FC = ( return ( { window.clearTimeout(skipDelayTimerRef.current); - setIsOpenDelayed(false); + isOpenDelayedRef.current = false; }, [])} onClose={React.useCallback(() => { window.clearTimeout(skipDelayTimerRef.current); skipDelayTimerRef.current = window.setTimeout( - () => setIsOpenDelayed(true), + () => isOpenDelayedRef.current = true, skipDelayDuration ); }, [skipDelayDuration])} @@ -229,9 +229,9 @@ const Tooltip: React.FC = (props: ScopedProps) => { trigger={trigger} onTriggerChange={setTrigger} onTriggerEnter={React.useCallback(() => { - if (providerContext.isOpenDelayed) handleDelayedOpen(); + if (providerContext.isOpenDelayedRef.current) handleDelayedOpen(); else handleOpen(); - }, [providerContext.isOpenDelayed, handleDelayedOpen, handleOpen])} + }, [providerContext.isOpenDelayedRef, handleDelayedOpen, handleOpen])} onTriggerLeave={React.useCallback(() => { if (disableHoverableContent) { handleClose();