Skip to content

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

Closed
@DrYurii

Description

@DrYurii

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions