Fix tooltip not closing (#34001)

* Fix tooltip not closing

* make this a bit less hacky

* use a more specific element for the mouseleave event

* Make sure we limit running of effect

* Remove console log

* Probably don't need useCallback
This commit is contained in:
Oscar Kilhed 2021-05-12 19:52:19 +02:00 committed by GitHub
parent ca213ce9ad
commit 1b5f1bfe33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -47,6 +47,22 @@ export const TooltipPlugin: React.FC<TooltipPluginProps> = ({
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) {