Skip to content

Commit

Permalink
fix: input loses focus on unmount (#212)
Browse files Browse the repository at this point in the history
  • Loading branch information
nihgwu committed Aug 12, 2020
1 parent 393ccfe commit b513ce0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## NEXT VERSION

- fix: input loses focus on unmount

## v1.10.8 (2020-08-11)

- fix: scroll position would be reset to top if column becomes frozen
Expand Down
14 changes: 10 additions & 4 deletions src/ColumnResizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,26 @@ export function addUserSelectStyles(doc) {
styleEl = doc.createElement('style');
styleEl.type = 'text/css';
styleEl.id = 'react-draggable-style-el';
styleEl.innerHTML = '.react-draggable-transparent-selection *::-moz-selection {background: transparent;}\n';
styleEl.innerHTML += '.react-draggable-transparent-selection *::selection {background: transparent;}\n';
styleEl.innerHTML = '.react-draggable-transparent-selection *::-moz-selection {all: inherit;}\n';
styleEl.innerHTML += '.react-draggable-transparent-selection *::selection {all: inherit;}\n';
doc.getElementsByTagName('head')[0].appendChild(styleEl);
}
if (doc.body) addClassName(doc.body, 'react-draggable-transparent-selection');
}

export function removeUserSelectStyles(doc) {
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');
if (doc.selection) {
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
Expand Down

0 comments on commit b513ce0

Please sign in to comment.