Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

withNextInputAutoFocus doen't work with custom components at all #102

Closed
DrYurii opened this issue Mar 19, 2019 · 3 comments
Closed

withNextInputAutoFocus doen't work with custom components at all #102

DrYurii opened this issue Mar 19, 2019 · 3 comments

Comments

@DrYurii
Copy link

DrYurii commented Mar 19, 2019

I wasted all day trying to get it to work with a custom input component and all the difference I could make is to either make the form submit by tapping Next button, or to defocus the field. Unlike the other issue here I don't even have any nesting. Unlike TextField and inbuilt native inputs it won't work in any way if I use a custom element that is seemingly compliant with the requirements set in readme. Here's the element wrapper:

export default class StyledInput extends React.Component {

  constructor(props) {
    super(props);
  }

  focus = () => this.setState({ focused: true });

  render() {
    return (
      <TextField {...this.props} />
    );
  }
}

Here's how it used:

const Form = withNextInputAutoFocusForm(View);
const MyInput = withNextInputAutoFocusInput(StyledInput);

export default class Login extends Screen {
...
  render() {
    return (
      <View >
          <Formik
            onSubmit={(values, actions) => this.formSubmit(values, actions)}
            validationSchema={validationSchema}
            initialValues={{
              ...
            }}
            render={formikProps => {
              return (
                <Form>

                  <MyInput
                    label='Blah'
                    autoFocus
                    name='login'
                    type='email'
                  />

                  <MyInput
                    label='Password'
                    name='password'
                    type='password'
                  />

                </Form>
              );
            }}
          />
        </View>
    );
  }
}

Am I doing something wrong or is it really broken?

@Almouro
Copy link
Member

Almouro commented Mar 20, 2019

Hi @BerekHalfhand,
Thanks for posting an issue and sorry for the waste of time! 🙏

I created a pull request to make the doc a bit clearer: https://github.com/bamlab/react-native-formik/pull/104/files, let me know if that helps!

Basically, your focus function needs to do something.
When clicking on next on the keyboard, the next component focus function is automatically called. But in your case, the function doesn't do anything and the keyboard is incidentally closed.

See example slack

Let me know if you have any further questions! 👍

@DrYurii
Copy link
Author

DrYurii commented Mar 22, 2019

@Almouro Hey, that actually works! Thanks a bunch mate, you made my day!
Now the docs must be updated to prevent this issue from happening to someone else. Will close it after the pull request gets merged.

@DrYurii
Copy link
Author

DrYurii commented Mar 22, 2019

Thank you

@DrYurii DrYurii closed this as completed Mar 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants