Skip to content

Commit

Permalink
Listen to mouse move events when dragging offscreen (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
taneliang authored Aug 5, 2020
1 parent 7f65c60 commit fe1c11d
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/useCanvasInteraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export function useCanvasInteraction(
});
};

const onCanvasMouseMove: MouseEventHandler = event => {
const onDocumentMouseMove: MouseEventHandler = event => {
interactor({
type: 'mousemove',
payload: {
Expand Down Expand Up @@ -174,18 +174,18 @@ export function useCanvasInteraction(
return false;
};

document.addEventListener('mousemove', onDocumentMouseMove);
document.addEventListener('mouseup', onDocumentMouseUp);

canvas.addEventListener('wheel', onCanvasWheel);
canvas.addEventListener('mousedown', onCanvasMouseDown);
canvas.addEventListener('mousemove', onCanvasMouseMove);
canvas.addEventListener('wheel', onCanvasWheel);

return () => {
document.removeEventListener('mousemove', onDocumentMouseMove);
document.removeEventListener('mouseup', onDocumentMouseUp);

canvas.removeEventListener('wheel', onCanvasWheel);
canvas.removeEventListener('mousedown', onCanvasMouseDown);
canvas.removeEventListener('mousemove', onCanvasMouseMove);
canvas.removeEventListener('wheel', onCanvasWheel);
};
}, [canvasRef, interactor]);
}

0 comments on commit fe1c11d

Please sign in to comment.