Skip to content

Commit

Permalink
reduce scope of mousemove listener
Browse files Browse the repository at this point in the history
  • Loading branch information
joshfarrant committed Jan 6, 2025
1 parent 8f38daa commit 18707d8
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/react/src/VideoPlayer/components/Range/Range.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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])

Expand Down

0 comments on commit 18707d8

Please sign in to comment.