[react-events] Fix isTargetWithinNode type (#16671)
isTargetWithinNode passes the childTarget to getClosestInstanceFromNode which does not account for a null value of 'node'.
Nicolas Gallagher committed
Sep 5, 2019 at 11:36 UTC
ff006451ad792ed26793691402bf7b5f813205f7
3 files changed
+11
-15
packages/react-dom/src/events/DOMEventResponderSystem.js
+1
-1
@@ -158,7 +158,7 @@ const eventResponderContext: ReactDOMResponderContext = {
158
return false;
159
},
160
isTargetWithinNode(
161
- childTarget: null | Element | Document,
161
+ childTarget: Element | Document,
162
parentTarget: Element | Document,
163
): boolean {
164
validateResponderContext();
packages/react-events/src/dom/Tap.js
+9
-13
@@ -321,22 +321,17 @@ function getHitTarget(
321
context: ReactDOMResponderContext,
322
state: TapState,
323
): null | Element | Document {
324
- if (hasPointerEvents) {
325
- return event.target;
326
- } else {
327
- if (event.pointerType === 'touch') {
328
- const doc = context.getActiveDocument();
329
- const nativeEvent: any = event.nativeEvent;
330
- const touch = getTouchById(nativeEvent, state.activePointerId);
331
- if (touch != null) {
332
- return doc.elementFromPoint(touch.clientX, touch.clientY);
333
- } else {
334
- return null;
335
- }
324
+ if (!hasPointerEvents && event.pointerType === 'touch') {
325
+ const doc = context.getActiveDocument();
326
+ const nativeEvent: any = event.nativeEvent;
327
+ const touch = getTouchById(nativeEvent, state.activePointerId);
328
+ if (touch != null) {
329
+ return doc.elementFromPoint(touch.clientX, touch.clientY);
330
} else {
337
- return event.target;
331
+ return null;
332
}
333
}
334
+ return event.target;
335
}
336
337
function isActivePointer(
@@ -617,6 +612,7 @@ const responderImpl = {
612
case 'scroll': {
613
if (
614
state.isActive &&
615
+ state.responderTarget != null &&
616
// We ignore incoming scroll events when using mouse events
617
state.pointerType !== 'mouse' &&
618
// If the scroll target is the document or if the pointer target
packages/shared/ReactDOMTypes.js
+1
-1
@@ -55,7 +55,7 @@ export type ReactDOMResponderContext = {
55
eventPriority: EventPriority,
56
) => void,
57
isTargetWithinNode: (
58
- childTarget: null | Element | Document,
58
+ childTarget: Element | Document,
59
parentTarget: Element | Document,
60
) => boolean,
61
isTargetWithinResponder: (null | Element | Document) => boolean,