question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

how to focus next Input onSubmitEditing using useRef

See original GitHub issue

unable to focus next input when pressed enter.

const attNameRef = useRef(null);

<Input 
    getRef={input => {
       attNameRef= input;
    }}
   onSubmitEditing={() => {
       attNameRef._root.focus();
    }}
/>

undefined is not obj

how can I use onSubmitEditing with useRef?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
thehappydinoacommented, Mar 30, 2020

I think I figured it out:

const passwordInput = useRef(null);

return (
<Container style={styles.container}>
      ...
      <Item rounded style={styles.input}>
        <Input
          onSubmitEditing={() => passwordInput.current._root.focus()}
          returnKeyType={'next'}
        />
      </Item>
      <Item rounded style={styles.input}>
        <Input
          ref={passwordInput}
        />
      </Item>
    ...
    </Container>
)
5reactions
Mohammad-Khalid23commented, Oct 11, 2019
  //use this function to focus on next field
  focusNextField = (id) => {
   this.inputs[id]._root.focus();
   }


      <Input
            keyboardType="email-address"
            name="email"
            onChangeText={(text) => this.setState({ email: text })}
            onSubmitEditing={() => {
              this.focusNextField('password');
            }}
            returnKeyType={"next"}
            ref={input => {
              this.inputs['email'] = input;
            }}
          />

          <Input
            name="password"
            onSubmitEditing={() => {
              this.loginSubmit()
            }}
            returnKeyType={"done"}
            ref={input => {
              this.inputs['password'] = input;
            }}
          />
Read more comments on GitHub >

github_iconTop Results From Across the Web

React Native: How to select the next TextInput after pressing ...
Bind focus function to first TextInput's onSubmitEditing event. ... import React, { useRef } from 'react' ... const MyFormComponent = () => {...
Read more >
Focus on the Next TextInput when Next Keyboard Button is ...
The first step is getting a ref to our Last Name input. The one we want to focus on after our first input...
Read more >
[Solved]-How focus the next field input in react native?-Reactjs
Coding example for the question How focus the next field input in react native? ... import React, { useRef } from 'react'; ......
Read more >
Focusing Next Input in React Native - David Tran
// ... render() { return ( <TextInput blurOnSubmit={false} onSubmitEditing={() => this.passwordRef.focus()} /> <TextInput ref={ref => this.
Read more >
4 Ways to Set Focus on an Input Field After Rendering in React
1. Autofocus in HTML · 2. Setting up React project · 3. Autofocus using React Hooks useRef · 4. Autofocus using React class...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found