File tree Expand file tree Collapse file tree 5 files changed +89
-0
lines changed
fixtures/dom/src/components
packages/react-dom/src/events Expand file tree Collapse file tree 5 files changed +89
-0
lines changed Original file line number Diff line number Diff line change @@ -65,6 +65,7 @@ class Header extends React.Component {
6565 < option value = "/custom-elements" > Custom Elements</ option >
6666 < option value = "/media-events" > Media Events</ option >
6767 < option value = "/pointer-events" > Pointer Events</ option >
68+ < option value = "/mouse-events" > Mouse Events</ option >
6869 </ select >
6970 </ label >
7071 < label htmlFor = "react_version" >
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import EventPooling from './event-pooling';
1212import CustomElementFixtures from './custom-elements' ;
1313import MediaEventsFixtures from './media-events' ;
1414import PointerEventsFixtures from './pointer-events' ;
15+ import MouseEventsFixtures from './mouse-events' ;
1516
1617const React = window . React ;
1718
@@ -49,6 +50,8 @@ function FixturesPage() {
4950 return < MediaEventsFixtures /> ;
5051 case '/pointer-events' :
5152 return < PointerEventsFixtures /> ;
53+ case '/mouse-events' :
54+ return < MouseEventsFixtures /> ;
5255 default :
5356 return < p > Please select a test fixture.</ p > ;
5457 }
Original file line number Diff line number Diff line change 1+ import FixtureSet from '../../FixtureSet' ;
2+ import MouseMovement from './mouse-movement' ;
3+
4+ const React = window . React ;
5+
6+ class MouseEvents extends React . Component {
7+ render ( ) {
8+ return (
9+ < FixtureSet title = "Mouse Events" description = "" >
10+ < MouseMovement />
11+ </ FixtureSet >
12+ ) ;
13+ }
14+ }
15+
16+ export default MouseEvents ;
Original file line number Diff line number Diff line change 1+ import TestCase from '../../TestCase' ;
2+
3+ const React = window . React ;
4+
5+ class MouseMovement extends React . Component {
6+ state = {
7+ movement : { x : 0 , y : 0 } ,
8+ } ;
9+
10+ onMove = event => {
11+ this . setState ( { x : event . movementX , y : event . movementY } ) ;
12+ } ;
13+
14+ render ( ) {
15+ const { x, y} = this . state ;
16+
17+ const boxStyle = {
18+ padding : '10px 20px' ,
19+ border : '1px solid #d9d9d9' ,
20+ margin : '10px 0 20px' ,
21+ } ;
22+
23+ return (
24+ < TestCase
25+ title = "Mouse Movement"
26+ description = "We polyfill the movementX and movementY fields."
27+ affectedBrowsers = "IE, Safari" >
28+ < TestCase . Steps >
29+ < li > Mouse over the box below</ li >
30+ </ TestCase . Steps >
31+
32+ < TestCase . ExpectedResult >
33+ The reported values should equal the pixel (integer) difference
34+ between mouse movements positions.
35+ </ TestCase . ExpectedResult >
36+
37+ < div style = { boxStyle } onMouseMove = { this . onMove } >
38+ < p > Trace your mouse over this box.</ p >
39+ < p >
40+ Last movement: { x } ,{ y }
41+ </ p >
42+ </ div >
43+ </ TestCase >
44+ ) ;
45+ }
46+ }
47+
48+ export default MouseMovement ;
Original file line number Diff line number Diff line change 88import SyntheticUIEvent from './SyntheticUIEvent' ;
99import getEventModifierState from './getEventModifierState' ;
1010
11+ let previousScreenX = null ;
12+ let previousScreenY = null ;
13+
1114/**
1215 * @interface MouseEvent
1316 * @see http://www.w3.org/TR/DOM-Level-3-Events/
@@ -34,6 +37,24 @@ const SyntheticMouseEvent = SyntheticUIEvent.extend({
3437 : event . fromElement )
3538 ) ;
3639 } ,
40+ movementX : function ( event ) {
41+ if ( 'movementX' in event ) {
42+ return event . movementX ;
43+ }
44+
45+ const screenX = previousScreenX ;
46+ previousScreenX = event . screenX ;
47+ return screenX ? event . screenX - screenX : 0 ;
48+ } ,
49+ movementY : function ( event ) {
50+ if ( 'movementY' in event ) {
51+ return event . movementY ;
52+ }
53+
54+ const screenY = previousScreenY ;
55+ previousScreenY = event . screenY ;
56+ return screenY ? event . screenY - screenY : 0 ;
57+ } ,
3758} ) ;
3859
3960export default SyntheticMouseEvent ;
You can’t perform that action at this time.
0 commit comments