Skip to content

Commit

Permalink
Code review-based cleanup and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
acusti committed Nov 17, 2017
1 parent 174375c commit 885aab7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
5 changes: 1 addition & 4 deletions packages/react-dom/src/client/ReactInputSelection.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,7 @@ export function restoreSelection(priorSelectionInformation) {
}
});

if (
curActiveElement !== priorActiveElement &&
isInDocument(priorActiveElement)
) {
if (curActiveElement !== priorActiveElement) {
focusNodePreservingScroll(priorActiveElement);
}
}
Expand Down
26 changes: 16 additions & 10 deletions packages/react-dom/src/events/SelectEventPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,20 @@ function getSelection(node) {
}
}

/**
* Get document associated with the event target.
*
* @param {object} nativeEventTarget
* @return {Document}
*/
function getEventTargetDocument(eventTarget) {
return eventTarget.window === eventTarget
? eventTarget.document
: eventTarget.nodeType === DOCUMENT_NODE
? eventTarget
: eventTarget.ownerDocument;
}

/**
* Poll selection to see whether it's changed.
*
Expand All @@ -93,10 +107,7 @@ function constructSelectEvent(nativeEvent, nativeEventTarget) {
// selection (this matches native `select` event behavior). In HTML5, select
// fires only on input and textarea thus if there's no focused element we
// won't dispatch.
var doc =
nativeEventTarget.ownerDocument ||
nativeEventTarget.document ||
nativeEventTarget;
var doc = getEventTargetDocument(nativeEventTarget);

if (
mouseDown ||
Expand Down Expand Up @@ -152,12 +163,7 @@ var SelectEventPlugin = {
nativeEvent,
nativeEventTarget,
) {
var doc =
nativeEventTarget.window === nativeEventTarget
? nativeEventTarget.document
: nativeEventTarget.nodeType === DOCUMENT_NODE
? nativeEventTarget
: nativeEventTarget.ownerDocument;
var doc = getEventTargetDocument(nativeEventTarget);
// Track whether all listeners exists for this plugin. If none exist, we do
// not extract events. See #3639.
if (!doc || !isListeningToAllDependencies('onSelect', doc)) {
Expand Down

0 comments on commit 885aab7

Please sign in to comment.