Skip to content

Commit b513ce0

Browse files
authored
fix: input loses focus on unmount (#212)
1 parent 393ccfe commit b513ce0

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## NEXT VERSION
44

5+
- fix: input loses focus on unmount
6+
57
## v1.10.8 (2020-08-11)
68

79
- fix: scroll position would be reset to top if column becomes frozen

src/ColumnResizer.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,26 @@ export function addUserSelectStyles(doc) {
1313
styleEl = doc.createElement('style');
1414
styleEl.type = 'text/css';
1515
styleEl.id = 'react-draggable-style-el';
16-
styleEl.innerHTML = '.react-draggable-transparent-selection *::-moz-selection {background: transparent;}\n';
17-
styleEl.innerHTML += '.react-draggable-transparent-selection *::selection {background: transparent;}\n';
16+
styleEl.innerHTML = '.react-draggable-transparent-selection *::-moz-selection {all: inherit;}\n';
17+
styleEl.innerHTML += '.react-draggable-transparent-selection *::selection {all: inherit;}\n';
1818
doc.getElementsByTagName('head')[0].appendChild(styleEl);
1919
}
2020
if (doc.body) addClassName(doc.body, 'react-draggable-transparent-selection');
2121
}
2222

2323
export function removeUserSelectStyles(doc) {
24+
if (!doc) return;
2425
try {
25-
if (doc && doc.body) removeClassName(doc.body, 'react-draggable-transparent-selection');
26+
if (doc.body) removeClassName(doc.body, 'react-draggable-transparent-selection');
2627
if (doc.selection) {
2728
doc.selection.empty();
2829
} else {
29-
window.getSelection().removeAllRanges(); // remove selection caused by scroll
30+
// Remove selection caused by scroll, unless it's a focused input
31+
// (we use doc.defaultView in case we're in an iframe)
32+
const selection = (doc.defaultView || window).getSelection();
33+
if (selection && selection.type !== 'Caret') {
34+
selection.removeAllRanges();
35+
}
3036
}
3137
} catch (e) {
3238
// probably IE

0 commit comments

Comments
 (0)