Fix onGot/LostPointerCapture events (#19487)
Dan Abramov committed
Jul 29, 2020 at 21:54 UTC
dff97a6915ef3a3897f85e3e47ffa55d4714ae72
2 files changed
+11
-6
packages/react-dom/src/__tests__/ReactDOMEventPropagation-test.js
+2
-4
@@ -347,8 +347,7 @@ describe('ReactDOMEventListener', () => {
347
});
348
});
349
350
- // TODO: this has regressed. Fix me.
351
- it.skip('onGotPointerCapture', () => {
350
+ it('onGotPointerCapture', () => {
351
testNativeBubblingEvent({
352
type: 'div',
353
reactEvent: 'onGotPointerCapture',
@@ -413,8 +412,7 @@ describe('ReactDOMEventListener', () => {
412
});
413
});
414
416
- // TODO: this has regressed. Fix me.
417
- it.skip('onLostPointerCapture', () => {
415
+ it('onLostPointerCapture', () => {
416
testNativeBubblingEvent({
417
type: 'div',
418
reactEvent: 'onLostPointerCapture',
packages/react-dom/src/events/DOMPluginEventSystem.js
+9
-2
@@ -470,8 +470,15 @@ export function listenToReactEvent(
470
}
471
}
472
} else {
473
- // Check if the react event ends in "Capture"
474
- const isCapturePhaseListener = reactEvent.substr(-7) === 'Capture';
473
+ const isCapturePhaseListener =
474
+ reactEvent.substr(-7) === 'Capture' &&
475
+ // Edge case: onGotPointerCapture and onLostPointerCapture
476
+ // end with "Capture" but that's part of their event names.
477
+ // The Capture versions would end with CaptureCapture.
478
+ // So we have to check against that.
479
+ // This check works because none of the events we support
480
+ // end with "Pointer".
481
+ reactEvent.substr(-14, 7) !== 'Pointer';
482
listenToNativeEvent(
483
dependencies[0],
484
isCapturePhaseListener,