Skip to content

Commit 5b3d17a

Browse files
jasonwilliamsgaearon
authored andcommitted
setting a flag, so that the first movement will have the correct value (#13082)
1 parent b0f6089 commit 5b3d17a

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

packages/react-dom/src/events/SyntheticMouseEvent.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@
88
import SyntheticUIEvent from './SyntheticUIEvent';
99
import getEventModifierState from './getEventModifierState';
1010

11-
let previousScreenX = null;
12-
let previousScreenY = null;
11+
let previousScreenX = 0;
12+
let previousScreenY = 0;
13+
// Use flags to signal movementX/Y has already been set
14+
let isMovementXSet = false;
15+
let isMovementYSet = false;
1316

1417
/**
1518
* @interface MouseEvent
@@ -44,7 +47,13 @@ const SyntheticMouseEvent = SyntheticUIEvent.extend({
4447

4548
const screenX = previousScreenX;
4649
previousScreenX = event.screenX;
47-
return screenX ? event.screenX - screenX : 0;
50+
51+
if (!isMovementXSet) {
52+
isMovementXSet = true;
53+
return 0;
54+
}
55+
56+
return event.screenX - screenX;
4857
},
4958
movementY: function(event) {
5059
if ('movementY' in event) {
@@ -53,7 +62,13 @@ const SyntheticMouseEvent = SyntheticUIEvent.extend({
5362

5463
const screenY = previousScreenY;
5564
previousScreenY = event.screenY;
56-
return screenY ? event.screenY - screenY : 0;
65+
66+
if (!isMovementYSet) {
67+
isMovementYSet = true;
68+
return 0;
69+
}
70+
71+
return event.screenY - screenY;
5772
},
5873
});
5974

0 commit comments

Comments
 (0)