diff --git a/packages/grafana-ui/src/components/uPlot/plugins/TooltipPlugin.tsx b/packages/grafana-ui/src/components/uPlot/plugins/TooltipPlugin.tsx index f4274d80eac..f47116796f1 100644 --- a/packages/grafana-ui/src/components/uPlot/plugins/TooltipPlugin.tsx +++ b/packages/grafana-ui/src/components/uPlot/plugins/TooltipPlugin.tsx @@ -47,6 +47,22 @@ export const TooltipPlugin: React.FC = ({ pluginLog(pluginId, true, `Focused series: ${focusedSeriesIdx}, focused point: ${focusedPointIdx}`); }, [focusedPointIdx, focusedSeriesIdx]); + useEffect(() => { + const plotMouseLeave = () => { + setCoords(null); + }; + + if (plotCtx && plotCtx.plot) { + plotCtx.plot.root.querySelector('.u-over')!.addEventListener('mouseleave', plotMouseLeave); + } + + return () => { + if (plotCtx && plotCtx.plot) { + plotCtx.plot.root.querySelector('.u-over')!.removeEventListener('mouseleave', plotMouseLeave); + } + }; + }, [plotCtx.plot?.root, setCoords]); + // Add uPlot hooks to the config, or re-add when the config changed useLayoutEffect(() => { if (config.tooltipInterpolator) {