[Flare] Clear pressStart timeout on pointercancel (#16067)

This commit is contained in:
Vincent Riemer
2019-07-05 11:45:33 +01:00
committed by Dominic Gannaway
parent c40075a72c
commit bd72b04939
2 changed files with 20 additions and 0 deletions
+4
View File
@@ -434,6 +434,10 @@ function dispatchCancel(
state: PressState,
): void {
state.touchEvent = null;
if (state.pressStartTimeout !== null) {
context.clearTimeout(state.pressStartTimeout);
state.pressStartTimeout = null;
}
if (state.isPressed) {
state.ignoreEmulatedMouseEvents = false;
dispatchPressEndEvents(event, context, props, state);
@@ -257,6 +257,22 @@ describe('Event responder: Press', () => {
ref.current.dispatchEvent(createEvent('pointerdown'));
expect(onPressStart).toHaveBeenCalledTimes(1);
});
it('onPressStart should not be called if pointerCancel is fired before delayPressStart is finished', () => {
const element = (
<Press delayPressStart={500} onPressStart={onPressStart}>
<div ref={ref} />
</Press>
);
ReactDOM.render(element, container);
ref.current.dispatchEvent(createEvent('pointerdown'));
jest.advanceTimersByTime(499);
expect(onPressStart).toHaveBeenCalledTimes(0);
ref.current.dispatchEvent(createEvent('pointercancel'));
jest.runAllTimers();
expect(onPressStart).toHaveBeenCalledTimes(0);
});
});
describe('delayPressEnd', () => {