Skip to content

Commit

Permalink
[react-events] Fix isTargetWithinNode type (#16671)
Browse files Browse the repository at this point in the history
isTargetWithinNode passes the childTarget to getClosestInstanceFromNode which
does not account for a null value of 'node'.
  • Loading branch information
necolas committed Sep 5, 2019
1 parent 040ca0f commit ff00645
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
2 changes: 1 addition & 1 deletion packages/react-dom/src/events/DOMEventResponderSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ const eventResponderContext: ReactDOMResponderContext = {
return false;
},
isTargetWithinNode(
childTarget: null | Element | Document,
childTarget: Element | Document,
parentTarget: Element | Document,
): boolean {
validateResponderContext();
Expand Down
22 changes: 9 additions & 13 deletions packages/react-events/src/dom/Tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,22 +321,17 @@ function getHitTarget(
context: ReactDOMResponderContext,
state: TapState,
): null | Element | Document {
if (hasPointerEvents) {
return event.target;
} else {
if (event.pointerType === 'touch') {
const doc = context.getActiveDocument();
const nativeEvent: any = event.nativeEvent;
const touch = getTouchById(nativeEvent, state.activePointerId);
if (touch != null) {
return doc.elementFromPoint(touch.clientX, touch.clientY);
} else {
return null;
}
if (!hasPointerEvents && event.pointerType === 'touch') {
const doc = context.getActiveDocument();
const nativeEvent: any = event.nativeEvent;
const touch = getTouchById(nativeEvent, state.activePointerId);
if (touch != null) {
return doc.elementFromPoint(touch.clientX, touch.clientY);
} else {
return event.target;
return null;
}
}
return event.target;
}

function isActivePointer(
Expand Down Expand Up @@ -617,6 +612,7 @@ const responderImpl = {
case 'scroll': {
if (
state.isActive &&
state.responderTarget != null &&
// We ignore incoming scroll events when using mouse events
state.pointerType !== 'mouse' &&
// If the scroll target is the document or if the pointer target
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/ReactDOMTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export type ReactDOMResponderContext = {
eventPriority: EventPriority,
) => void,
isTargetWithinNode: (
childTarget: null | Element | Document,
childTarget: Element | Document,
parentTarget: Element | Document,
) => boolean,
isTargetWithinResponder: (null | Element | Document) => boolean,
Expand Down

0 comments on commit ff00645

Please sign in to comment.