diff --git a/fixtures/dom/src/components/Header.js b/fixtures/dom/src/components/Header.js index fbb2e6e505b39..4a7b1513e66cb 100644 --- a/fixtures/dom/src/components/Header.js +++ b/fixtures/dom/src/components/Header.js @@ -64,6 +64,7 @@ class Header extends React.Component { Event Pooling Custom Elements Media Events + Pointer Events diff --git a/fixtures/dom/src/components/fixtures/index.js b/fixtures/dom/src/components/fixtures/index.js index 9b40eb9b1f857..d43a94df3418b 100644 --- a/fixtures/dom/src/components/fixtures/index.js +++ b/fixtures/dom/src/components/fixtures/index.js @@ -11,6 +11,7 @@ import ErrorHandling from './error-handling'; import EventPooling from './event-pooling'; import CustomElementFixtures from './custom-elements'; import MediaEventsFixtures from './media-events'; +import PointerEventsFixtures from './pointer-events'; const React = window.React; @@ -46,6 +47,8 @@ function FixturesPage() { return ; case '/media-events': return ; + case '/pointer-events': + return ; default: return Please select a test fixture.; } diff --git a/fixtures/dom/src/components/fixtures/pointer-events/drag-box.js b/fixtures/dom/src/components/fixtures/pointer-events/drag-box.js new file mode 100644 index 0000000000000..0bbc894ccc0e7 --- /dev/null +++ b/fixtures/dom/src/components/fixtures/pointer-events/drag-box.js @@ -0,0 +1,90 @@ +const React = window.React; + +const CIRCLE_SIZE = 80; + +class DragBox extends React.Component { + state = { + hasCapture: false, + circleLeft: 80, + circleTop: 80, + }; + isDragging = false; + previousLeft = 0; + previousTop = 0; + + onDown = event => { + this.isDragging = true; + event.target.setPointerCapture(event.pointerId); + + // We store the initial coordinates to be able to calculate the changes + // later on. + this.extractPositionDelta(event); + }; + + onMove = event => { + if (!this.isDragging) { + return; + } + const {left, top} = this.extractPositionDelta(event); + + this.setState(({circleLeft, circleTop}) => ({ + circleLeft: circleLeft + left, + circleTop: circleTop + top, + })); + }; + + onUp = event => (this.isDragging = false); + onGotCapture = event => this.setState({hasCapture: true}); + onLostCapture = event => this.setState({hasCapture: false}); + + extractPositionDelta = event => { + const left = event.pageX; + const top = event.pageY; + const delta = { + left: left - this.previousLeft, + top: top - this.previousTop, + }; + this.previousLeft = left; + this.previousTop = top; + return delta; + }; + + render() { + const {hasCapture, circleLeft, circleTop} = this.state; + + const boxStyle = { + border: '1px solid #d9d9d9', + margin: '10px 0 20px', + minHeight: 400, + width: '100%', + position: 'relative', + }; + + const circleStyle = { + width: CIRCLE_SIZE, + height: CIRCLE_SIZE, + borderRadius: CIRCLE_SIZE / 2, + position: 'absolute', + left: circleLeft, + top: circleTop, + backgroundColor: hasCapture ? 'blue' : 'green', + touchAction: 'none', + }; + + return ( + + + + ); + } +} + +export default DragBox; diff --git a/fixtures/dom/src/components/fixtures/pointer-events/drag.js b/fixtures/dom/src/components/fixtures/pointer-events/drag.js new file mode 100644 index 0000000000000..3c829cc657c77 --- /dev/null +++ b/fixtures/dom/src/components/fixtures/pointer-events/drag.js @@ -0,0 +1,25 @@ +import TestCase from '../../TestCase'; +import DragBox from './drag-box'; + +const React = window.React; + +class Drag extends React.Component { + render() { + return ( + + + Drag the circle below with any pointer tool + + + + While dragging, the circle must have turn blue to indicate that a + pointer capture was received. + + + + + ); + } +} + +export default Drag; diff --git a/fixtures/dom/src/components/fixtures/pointer-events/hover-box.js b/fixtures/dom/src/components/fixtures/pointer-events/hover-box.js new file mode 100644 index 0000000000000..4fa4a07e65b33 --- /dev/null +++ b/fixtures/dom/src/components/fixtures/pointer-events/hover-box.js @@ -0,0 +1,34 @@ +const React = window.React; + +class DrawBox extends React.Component { + render() { + const boxStyle = { + border: '1px solid #d9d9d9', + margin: '10px 0 20px', + padding: '20px 20px', + touchAction: 'none', + }; + + const obstacleStyle = { + border: '1px solid #d9d9d9', + width: '25%', + height: '200px', + margin: '12.5%', + display: 'inline-block', + }; + + return ( + + + + + ); + } +} + +export default DrawBox; diff --git a/fixtures/dom/src/components/fixtures/pointer-events/hover.js b/fixtures/dom/src/components/fixtures/pointer-events/hover.js new file mode 100644 index 0000000000000..f64eff82e3523 --- /dev/null +++ b/fixtures/dom/src/components/fixtures/pointer-events/hover.js @@ -0,0 +1,51 @@ +import TestCase from '../../TestCase'; +import HoverBox from './hover-box'; + +const React = window.React; + +class Hover extends React.Component { + state = { + overs: 0, + outs: 0, + enters: 0, + leaves: 0, + }; + + onOver = () => this.setState({overs: this.state.overs + 1}); + onOut = () => this.setState({outs: this.state.outs + 1}); + onEnter = () => this.setState({enters: this.state.enters + 1}); + onLeave = () => this.setState({leaves: this.state.leaves + 1}); + + render() { + const {overs, outs, enters, leaves} = this.state; + + return ( + + + Hover over the above box and the obstacles + + + + Overs and outs should increase when moving over the obstacles but + enters and leaves should not. + + + + + + Pointer Overs: {overs} + Pointer Outs: {outs} + Pointer Enters: {enters} + Pointer Leaves: {leaves} + + + ); + } +} + +export default Hover; diff --git a/fixtures/dom/src/components/fixtures/pointer-events/index.js b/fixtures/dom/src/components/fixtures/pointer-events/index.js new file mode 100644 index 0000000000000..cad6cdfef1630 --- /dev/null +++ b/fixtures/dom/src/components/fixtures/pointer-events/index.js @@ -0,0 +1,20 @@ +import FixtureSet from '../../FixtureSet'; +import Drag from './drag'; +import Hover from './hover'; + +const React = window.React; + +class PointerEvents extends React.Component { + render() { + return ( + + + + + ); + } +} + +export default PointerEvents;
Please select a test fixture.
+ Pointer Overs: {overs} + Pointer Outs: {outs} + Pointer Enters: {enters} + Pointer Leaves: {leaves} +