[Flare] Press: fix middle-click handling (#16114)

Make sure the root events are removed after middle-click completes
This commit is contained in:
Nicolas Gallagher 2019-07-11 22:12:10 +01:00 committed by GitHub
parent 3f1dee09a4
commit ca4d78f9b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 4 deletions

View File

@ -893,6 +893,7 @@ const PressResponder: ReactDOMEventResponder = {
case 'mouseup':
case 'touchend': {
if (isPressed) {
const button = nativeEvent.button;
let isKeyboardEvent = false;
let touchEvent;
if (type === 'pointerup' && activePointerId !== pointerId) {
@ -911,6 +912,9 @@ const PressResponder: ReactDOMEventResponder = {
}
isKeyboardEvent = true;
removeRootEventTypes(context, state);
} else if (button === 1) {
// Remove the root events here as no 'click' event is dispatched when this 'button' is pressed.
removeRootEventTypes(context, state);
}
// Determine whether to call preventDefault on subsequent native events.
@ -968,10 +972,7 @@ const PressResponder: ReactDOMEventResponder = {
state,
);
}
if (
state.isPressWithinResponderRegion &&
nativeEvent.button !== 1
) {
if (state.isPressWithinResponderRegion && button !== 1) {
if (
!(
wasLongPressed &&

View File

@ -150,6 +150,48 @@ describe('Event responder: Press', () => {
);
});
it('is not called after "pointermove" following auxillary-button press', () => {
ref.current.getBoundingClientRect = () => ({
top: 0,
left: 0,
bottom: 100,
right: 100,
});
ref.current.dispatchEvent(
createEvent('pointerdown', {
button: 1,
pointerType: 'mouse',
clientX: 50,
clientY: 50,
}),
);
ref.current.dispatchEvent(
createEvent('pointerup', {
button: 1,
pointerType: 'mouse',
clientX: 50,
clientY: 50,
}),
);
container.dispatchEvent(
createEvent('pointermove', {
button: 1,
pointerType: 'mouse',
clientX: 110,
clientY: 110,
}),
);
container.dispatchEvent(
createEvent('pointermove', {
button: 1,
pointerType: 'mouse',
clientX: 50,
clientY: 50,
}),
);
expect(onPressStart).toHaveBeenCalledTimes(1);
});
it('ignores browser emulated events', () => {
ref.current.dispatchEvent(createEvent('pointerdown'));
ref.current.dispatchEvent(createEvent('touchstart'));