diff --git a/lib/utils/domFns.js b/lib/utils/domFns.js index 6963da72..87809bd8 100644 --- a/lib/utils/domFns.js +++ b/lib/utils/domFns.js @@ -158,14 +158,20 @@ export function addUserSelectStyles(doc: ?Document) { } export function removeUserSelectStyles(doc: ?Document) { + if (!doc) return; try { - if (doc && doc.body) removeClassName(doc.body, 'react-draggable-transparent-selection'); + if (doc.body) removeClassName(doc.body, 'react-draggable-transparent-selection'); // $FlowIgnore: IE if (doc.selection) { // $FlowIgnore: IE doc.selection.empty(); } else { - window.getSelection().removeAllRanges(); // remove selection caused by scroll + // Remove selection caused by scroll, unless it's a focused input + // (we use doc.defaultView in case we're in an iframe) + const selection = (doc.defaultView || window).getSelection(); + if (selection && selection.type !== 'Caret') { + selection.removeAllRanges(); + } } } catch (e) { // probably IE