简体   繁体   English

在将焦点输入到下一个文本输入后

[英]after typing focus to next text input

let say I have 3 views with TextInput inside it. 假设我有3个带有TextInput视图。

<View style={styles.row}>
    <TextInput
        ref={'cell_'+i}
        maxLength={1}
        spellCheck={false}
        style={styles.chewy}
        onKeyPress={this._onInputFilled} />
</View>
<View style={styles.row}>
    <TextInput
        ref={'cell_'+i}
        maxLength={1}
        spellCheck={false}
        style={styles.chewy}
        onKeyPress={this._onInputFilled} />
</View>
<View style={styles.row}>
    <TextInput
        ref={'cell_'+i}
        maxLength={1}
        spellCheck={false}
        style={styles.chewy}
        onKeyPress={this._onInputFilled} />
</View>

notice ref={'cell_'+i} where i equal to 0..2. 注意ref={'cell_'+i} ,其中i等于0.2。 now when I type in a char inside cell_0 how to focus (move the cursor) to the next TextInput ie. 现在,当我在cell_0内键入一个char时,如何聚焦(移动光标)到下一个TextInput上。 cell_1 ? cell_1吗?

Try this code : 试试这个代码:

<View style={styles.row}>
    <TextInput
        ref={'cell_'+i}
        maxLength={1}
        spellCheck={false}
        style={styles.chewy}
        onKeyPress={this._onInputFilled}
        onSubmitEditing={() => this.focusNextField('cell_' + (i+1))}
        />
</View>
<View style={styles.row}>
    <TextInput
        ref={'cell_'+i}
        maxLength={1}
        spellCheck={false}
        style={styles.chewy}
        onKeyPress={this._onInputFilled}
        onSubmitEditing={() => this.focusNextField('cell_' + (i+1))}
        />
</View>
<View style={styles.row}>
    <TextInput
        ref={'cell_'+i}
        maxLength={1}
        spellCheck={false}
        style={styles.chewy}
        onKeyPress={this._onInputFilled}
        />
</View>

onSubmitEditing: onSubmitEditing:

focusNextField = nextField => {
   this.refs[nextField].focus();
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 输入字符后反应输入文本框失去焦点 - React input text box loses focus after typing a character 输入字符 React 后输入失去焦点 - Input loses focus after typing character React 将输入字段追加到其他容器后,除非再次单击,否则无法继续输入文本输入。 它失去焦点 - After appending input field to a different container, I cannot continue typing in the text input unless I click again. It loses focus 使用angularjs将焦点更改为下一个输入文本 - change focus to the next input text with angularjs React-以动态形式输入1个字符后输入失去焦点 - React - Input loses focus after typing 1 char in dynamic form 在 React 中,为什么输入框在输入字符后会失去焦点? - In React , why does the input field lose focus after typing a character? 输入一个数字后,React 输入字段失去焦点 - React input field lose focus after typing one number 在反应应用程序中输入一个字符后输入字段失去焦点 - Input field loses focus after typing one character in react app 如果其他输入文本没有焦点并且具有价值但如果我集中并输入文本仍然存在,如何删除文本 - how to delete a text if other input text not focus and have value but if i focus and typing the text still there 用于文本输入的AngularJS指令:专注于Enter上的下一个输入 - AngularJS directive for text input: focus on next input on Enter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM