How to clear focus from input field in React Native?

I have an input field, and I want to get rid of it after I click the "Submit" button.

Any suggestions on how I will do this?

+8
react-native
source share
3 answers

You can add ref to enter text: <TextInput ref="input"> , and then call this.refs.input.blur() .

+11
source share

This may not seem like an obvious answer, but you can try the static Keyboard.dismiss () method to do this. https://facebook.imtqy.com/react-native/docs/keyboard I needed to remove focus when it was not clear which input might have it. It did the trick.

+1
source share

In my use case, I clearly needed input to lose focus (and require the user to touch it again with the intention of editing).

Kladzh in this post was the best for me:

 this.refs.input.setNativeProps({'editable':false}); this.refs.input.setNativeProps({'editable':true}); 
0
source share

All Articles