reactjs - How to autofocus redux field -


i want autofocus first redux field. have tried many different options available none of them worked. whenever form gets created, should focus first field.

           <field               name={'email'}               label="email *"               onfocuscb={this.hidedonebutton}               component={forminput}               containerstyle={styles.inputstyle}               clearbuttonmode={'always'}               autocorrect={false}           /> 

i have created component{forminput} outside class. below code same.

const forminput = props => (<view style={props.containerstyle}> <formtextinput     autofocus={true}     multiline     style={props.style}     autocapitalize={props.autocapitalize}     clearbuttonmode={props.clearbuttonmode}     selectioncolor={props.selectioncolor}     value={props.input.value}     onfocus={props.onfocuscb}     keyboardtype={props.keyboardtype}     label={props.label}     placeholder={props.placeholder}     defaultvalue={props.defaultvalue}     onchangetext={text => props.input.onchange(text)}     onendediting={() => {       if (props.onendediting) {         props.onendediting();       }       if (props.input.onendediting) {         props.input.onendediting();       }     }} /> </view>); 

you use html5 attribute autofocus. solution not related redux form.

<field           autofocus           name={'email'}           label="email *"           onfocuscb={this.hidedonebutton}           component={forminput}           containerstyle={styles.inputstyle}           clearbuttonmode={'always'}           autocorrect={false}       /> 

there ways within redux-form, setting props ref, withref, use getrenderedcomponent() , calling .focus(), simple behavior it's not clear benefit, on using autofocus, be.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -