Christian Tchaikovsky
Christian Tchaikovsky

Reputation: 192

Trigger mousemove event outside of the component (React)

I want to trigger mousemove event if i went outside the element

Sandbox: https://codesandbox.io/s/smoosh-morning-r7lv24?file=/src/Range/Range.js

I want that when I click on the Thumb, it moves, even if I go outside the block

Upvotes: 0

Views: 1458

Answers (1)

DANIEL SSEJJEMBA
DANIEL SSEJJEMBA

Reputation: 405

I have modified your sandbox to allow moving the rail outside the component

Sandbox: link here

You need to attach listeners when the mouse is down and remove them when mouse is up. These listeners should be attached to the document so you can still listen outside the component. You can also improve this further to remove listeners when component is unmounted or when window is blurred.

Upvotes: 3

Related Questions