From 117ce59f279eb83c9367fcc354fb506ad5712268 Mon Sep 17 00:00:00 2001 From: Nicolas Gallagher Date: Wed, 15 Nov 2017 15:15:22 -0800 Subject: [PATCH] [fix] TextInput focus/blur management 1. Focusing/blurring a TextInput should update TextInputState. 2. Using the focus/blur instance methods should trigger related events. Close #715 --- src/components/TextInput/TextInputState.js | 12 ++++++++---- src/components/TextInput/index.js | 10 +++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/components/TextInput/TextInputState.js b/src/components/TextInput/TextInputState.js index f75cbb02..e0505fca 100644 --- a/src/components/TextInput/TextInputState.js +++ b/src/components/TextInput/TextInputState.js @@ -40,9 +40,11 @@ const TextInputState = { * noop if the text field was already focused */ focusTextInput(textFieldNode: ?Object) { - if (document.activeElement !== textFieldNode && textFieldNode !== null) { + if (textFieldNode !== null) { this._currentlyFocusedNode = textFieldNode; - UIManager.focus(textFieldNode); + if (document.activeElement !== textFieldNode) { + UIManager.focus(textFieldNode); + } } }, @@ -52,9 +54,11 @@ const TextInputState = { * noop if it wasn't focused */ blurTextInput(textFieldNode: ?Object) { - if (document.activeElement === textFieldNode && textFieldNode !== null) { + if (textFieldNode !== null) { this._currentlyFocusedNode = null; - UIManager.blur(textFieldNode); + if (document.activeElement === textFieldNode) { + UIManager.blur(textFieldNode); + } } } }; diff --git a/src/components/TextInput/index.js b/src/components/TextInput/index.js index 828d366b..2b3cf730 100644 --- a/src/components/TextInput/index.js +++ b/src/components/TextInput/index.js @@ -150,18 +150,12 @@ class TextInput extends Component { static State = TextInputState; - blur() { - TextInputState.blurTextInput(this._node); - } + blur: Function; clear() { this._node.value = ''; } - focus() { - TextInputState.focusTextInput(this._node); - } - isFocused() { return TextInputState.currentlyFocusedField() === this._node; } @@ -270,6 +264,7 @@ class TextInput extends Component { _handleBlur = e => { const { onBlur } = this.props; + TextInputState.blurTextInput(this._node); if (onBlur) { onBlur(e); } @@ -289,6 +284,7 @@ class TextInput extends Component { _handleFocus = e => { const { clearTextOnFocus, onFocus, selectTextOnFocus } = this.props; const node = this._node; + TextInputState.focusTextInput(this._node); if (onFocus) { onFocus(e); }