[Flare] Clear pressStart timeout on pointercancel (#16067)
Vincent Riemer committed
Jul 5, 2019 at 03:45 UTC
bd72b04939beccac393d2894eb22028a217fd7f3
2 files changed
+20
packages/react-events/src/dom/Press.js
+4
@@ -434,6 +434,10 @@ function dispatchCancel(
434
state: PressState,
435
): void {
436
state.touchEvent = null;
437
+ if (state.pressStartTimeout !== null) {
438
+ context.clearTimeout(state.pressStartTimeout);
439
+ state.pressStartTimeout = null;
440
+ }
441
if (state.isPressed) {
442
state.ignoreEmulatedMouseEvents = false;
443
dispatchPressEndEvents(event, context, props, state);
packages/react-events/src/dom/__tests__/Press-test.internal.js
+16
@@ -257,6 +257,22 @@ describe('Event responder: Press', () => {
257
ref.current.dispatchEvent(createEvent('pointerdown'));
258
expect(onPressStart).toHaveBeenCalledTimes(1);
259
});
260
+
261
+ it('onPressStart should not be called if pointerCancel is fired before delayPressStart is finished', () => {
262
+ const element = (
263
+ <Press delayPressStart={500} onPressStart={onPressStart}>
264
+ <div ref={ref} />
265
+ </Press>
266
+ );
267
+ ReactDOM.render(element, container);
268
+
269
+ ref.current.dispatchEvent(createEvent('pointerdown'));
270
+ jest.advanceTimersByTime(499);
271
+ expect(onPressStart).toHaveBeenCalledTimes(0);
272
+ ref.current.dispatchEvent(createEvent('pointercancel'));
273
+ jest.runAllTimers();
274
+ expect(onPressStart).toHaveBeenCalledTimes(0);
275
+ });
276
});
277
278
describe('delayPressEnd', () => {