Skip to content

Commit 39a9589

Browse files
committed
Code review-based cleanup and improvements
1 parent 174375c commit 39a9589

File tree

3 files changed

+20
-19
lines changed

3 files changed

+20
-19
lines changed

packages/react-dom/src/client/ReactInputSelection.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,7 @@ export function restoreSelection(priorSelectionInformation) {
164164
}
165165
});
166166

167-
if (
168-
curActiveElement !== priorActiveElement &&
169-
isInDocument(priorActiveElement)
170-
) {
167+
if (curActiveElement !== priorActiveElement) {
171168
focusNodePreservingScroll(priorActiveElement);
172169
}
173170
}

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,20 @@ function getSelection(node) {
8181
}
8282
}
8383

84+
/**
85+
* Get document associated with the event target.
86+
*
87+
* @param {object} nativeEventTarget
88+
* @return {Document}
89+
*/
90+
function getEventTargetDocument(eventTarget) {
91+
return eventTarget.window === eventTarget
92+
? eventTarget.document
93+
: eventTarget.nodeType === DOCUMENT_NODE
94+
? eventTarget
95+
: eventTarget.ownerDocument;
96+
}
97+
8498
/**
8599
* Poll selection to see whether it's changed.
86100
*
@@ -93,10 +107,7 @@ function constructSelectEvent(nativeEvent, nativeEventTarget) {
93107
// selection (this matches native `select` event behavior). In HTML5, select
94108
// fires only on input and textarea thus if there's no focused element we
95109
// won't dispatch.
96-
var doc =
97-
nativeEventTarget.ownerDocument ||
98-
nativeEventTarget.document ||
99-
nativeEventTarget;
110+
var doc = getEventTargetDocument(nativeEventTarget);
100111

101112
if (
102113
mouseDown ||
@@ -152,12 +163,7 @@ var SelectEventPlugin = {
152163
nativeEvent,
153164
nativeEventTarget,
154165
) {
155-
var doc =
156-
nativeEventTarget.window === nativeEventTarget
157-
? nativeEventTarget.document
158-
: nativeEventTarget.nodeType === DOCUMENT_NODE
159-
? nativeEventTarget
160-
: nativeEventTarget.ownerDocument;
166+
var doc = getEventTargetDocument(nativeEventTarget);
161167
// Track whether all listeners exists for this plugin. If none exist, we do
162168
// not extract events. See #3639.
163169
if (!doc || !isListeningToAllDependencies('onSelect', doc)) {

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@ import SyntheticEvent from 'events/SyntheticEvent';
1313
*/
1414
var ClipboardEventInterface = {
1515
clipboardData: function(event) {
16-
if ('clipboardData' in event) {
17-
return event.clipboardData;
18-
}
19-
var doc = (event.target && event.target.ownerDocument) || document;
20-
return doc.defaultView.clipboardData;
16+
return 'clipboardData' in event
17+
? event.clipboardData
18+
: window.clipboardData;
2119
},
2220
};
2321

0 commit comments

Comments
 (0)