Skip to content

Commit dff97a6

Browse files
authored
Fix onGot/LostPointerCapture events (facebook#19487)
1 parent eae90cd commit dff97a6

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

packages/react-dom/src/__tests__/ReactDOMEventPropagation-test.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,7 @@ describe('ReactDOMEventListener', () => {
347347
});
348348
});
349349

350-
// TODO: this has regressed. Fix me.
351-
it.skip('onGotPointerCapture', () => {
350+
it('onGotPointerCapture', () => {
352351
testNativeBubblingEvent({
353352
type: 'div',
354353
reactEvent: 'onGotPointerCapture',
@@ -413,8 +412,7 @@ describe('ReactDOMEventListener', () => {
413412
});
414413
});
415414

416-
// TODO: this has regressed. Fix me.
417-
it.skip('onLostPointerCapture', () => {
415+
it('onLostPointerCapture', () => {
418416
testNativeBubblingEvent({
419417
type: 'div',
420418
reactEvent: 'onLostPointerCapture',

packages/react-dom/src/events/DOMPluginEventSystem.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,8 +470,15 @@ export function listenToReactEvent(
470470
}
471471
}
472472
} 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';
475482
listenToNativeEvent(
476483
dependencies[0],
477484
isCapturePhaseListener,

0 commit comments

Comments
 (0)