Fix selection unfocus input bug (Fixes #366)

This commit is contained in:
Gregory Schier committed 2017-08-09 13:14:59 -07:00
1 parent 037ad21a19
commit 32ef288c6e
1 file changed
+6 -3
@@ -82,18 +82,21 @@ class OneLineEditor extends PureComponent {
}
componentDidMount () {
document.body.addEventListener('click', this._handleDocumentClick);
document.body.addEventListener('mousedown', this._handleDocumentMousedown);
}
componentWillUnmount () {
document.body.removeEventListener('click', this._handleDocumentClick);
document.body.removeEventListener('mousedown', this._handleDocumentMousedown);
}
_handleDocumentClick (e) {
_handleDocumentMousedown (e) {
if (!this._editor) {
return;
}
// Clear the selection if mousedown happens outside the input so we act like
// a regular <input>
// NOTE: Must be "mousedown", not "click" because "click" triggers on selection drags
const node = ReactDOM.findDOMNode(this._editor);
const clickWasOutsideOfComponent = !node.contains(e.target);
if (clickWasOutsideOfComponent) {