Skip to content

Commit

Permalink
adding movementX and movementY into syntheticMouseEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Williams committed Jun 11, 2018
1 parent c78957e commit 5b2676b
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions packages/react-dom/src/events/SyntheticMouseEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import SyntheticUIEvent from './SyntheticUIEvent';
import getEventModifierState from './getEventModifierState';

let previousScreenX = null;
let previousScreenY = null;

/**
* @interface MouseEvent
* @see http://www.w3.org/TR/DOM-Level-3-Events/
Expand All @@ -34,6 +37,24 @@ const SyntheticMouseEvent = SyntheticUIEvent.extend({
: event.fromElement)
);
},
movementX: function(event) {
if ('movementX' in event) {
return event.movementX;
}

const screenX = previousScreenX;
previousScreenX = event.ScreenX;
return screenX ? event.screenX - screenX : 0;
},
movementY: function(event) {
if ('movementY' in event) {
return event.movementY;
}

const screenY = previousScreenY;
previousScreenY = event.screenY;
return screenY ? event.screenY - screenY : 0;
},
});

export default SyntheticMouseEvent;

0 comments on commit 5b2676b

Please sign in to comment.