Listen on timeline ref instead of window (#18006)

This commit is contained in:
Josh Hawkins 2025-05-02 18:35:55 -05:00 committed by GitHub
parent 1a383c47b5
commit 5c3ac75c31
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -159,16 +159,30 @@ export function useTimelineZoom({
);
useEffect(() => {
window.addEventListener("wheel", handleWheel, { passive: false });
window.addEventListener("touchstart", handleTouchStart, { passive: false });
window.addEventListener("touchmove", handleTouchMove, { passive: false });
const timelineElement = timelineRef.current;
if (timelineElement) {
timelineElement.addEventListener("wheel", handleWheel, {
passive: false,
});
timelineElement.addEventListener("touchstart", handleTouchStart, {
passive: false,
});
timelineElement.addEventListener("touchmove", handleTouchMove, {
passive: false,
});
}
return () => {
window.removeEventListener("wheel", handleWheel);
window.removeEventListener("touchstart", handleTouchStart);
window.removeEventListener("touchmove", handleTouchMove);
if (timelineElement) {
timelineElement.removeEventListener("wheel", handleWheel);
timelineElement.removeEventListener("touchstart", handleTouchStart);
timelineElement.removeEventListener("touchmove", handleTouchMove);
}
};
}, [handleWheel, handleTouchStart, handleTouchMove]);
// we know that these deps are correct
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [handleWheel, handleTouchStart, handleTouchMove, timelineRef.current]);
return { zoomLevel, handleZoom, isZooming, zoomDirection };
}