From 18707d89a7b8604364f7e26a49dab740d0473812 Mon Sep 17 00:00:00 2001 From: Josh Farrant Date: Fri, 20 Dec 2024 08:51:24 +0000 Subject: [PATCH] reduce scope of mousemove listener --- .../react/src/VideoPlayer/components/Range/Range.tsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/react/src/VideoPlayer/components/Range/Range.tsx b/packages/react/src/VideoPlayer/components/Range/Range.tsx index 2670bb1af..f360e45f1 100644 --- a/packages/react/src/VideoPlayer/components/Range/Range.tsx +++ b/packages/react/src/VideoPlayer/components/Range/Range.tsx @@ -37,12 +37,14 @@ export const Range = ({ }, [startValue]) useEffect(() => { - if (!max || !tooltip || !inputRef.current) { + const input = inputRef.current + + if (!max || !tooltip || !input) { return } const handleMouseMove = event => { - if (event.target !== inputRef.current) { + if (event.target !== input) { setHoverValue(0) setMousePos(0) return @@ -53,10 +55,10 @@ export const Range = ({ setHoverValue((event.offsetX / event.target.clientWidth) * max) } - window.addEventListener('mousemove', handleMouseMove) + input.addEventListener('mousemove', handleMouseMove) return () => { - window.removeEventListener('mousemove', handleMouseMove) + input.removeEventListener('mousemove', handleMouseMove) } }, [max, tooltip, inputRef])