Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to clear TextInput focus in React Native? (Android)

how to clear TextInput focus in React Native? (Android)

I have look for an API here:

https://facebook.github.io/react-native/docs/textinput.html#content

But no result...

Anyone can help?

like image 963
Damon Yuan Avatar asked Oct 16 '15 03:10

Damon Yuan


People also ask

How do you remove TextInput focus in react native?

Wrap the View component that is the parent of the TextInput in a Pressable component and then pass Keyboard. dismiss to the onPress prop. So, if the user taps anywhere outside the TextInput field, it will trigger Keyboard. dismiss , which will result in the TextInput field losing focus and the keyboard being hidden.

How do I disable TextInput in react native?

Use caretHidden={true} if you want to disable all operation like Cut Paste Copy. It will also hide your cursor as well.

How do you focus TextInput in react native?

Two methods exposed via the native element are .focus() and .blur() that will focus or blur the TextInput programmatically.


1 Answers

I think this should work. Add the onFocus as a prop to your TextInput . This is assuming you have a state variable called text, and that the TextInput takes its value from that state variable.

<TextInput 
   ...
   onFocus= {() => this.setState({text : ''})}
   value={this.state.text}/>
like image 164
Ginandi Avatar answered Sep 29 '22 23:09

Ginandi