srb633
srb633

Reputation: 813

How to activate text input on press of a button in react native?

I'm creating a basic note pad app. In the app, the user can press a button to "add a note". When pressed, a modal is rendered displaying a text input for the user to type their note.

The issue I'm having is once the modal has opened, the user has to manually tap the text input to pull up the keyboard and type their note. Instead I want the text input to be activated automatically the moment the modal is displayed on press of the button. So in other words, allow the user to start typing their note, once the modal opens up.

So I assume I have to some how activate a text input on press of a button? Is this possible?

Thanks.

Upvotes: 1

Views: 2009

Answers (1)

Steven Bell
Steven Bell

Reputation: 1989

Use the autoFocus prop.

<TextInput autoFocus={true}

Note that the input will focus when the component is mounted, so you may want to render the modal conditionally.

Upvotes: 1

Related Questions