mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[Flare] Clear pressStart timeout on pointercancel (#16067)
This commit is contained in:
committed by
Dominic Gannaway
parent
c40075a72c
commit
bd72b04939
+4
@@ -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', () => {
|
||||
|
||||
Reference in New Issue
Block a user