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

Max length prop of TextInput is ignored #1239

Closed
pierrezimmermannbam opened this issue Nov 23, 2022 · 3 comments · Fixed by #1641
Closed

Max length prop of TextInput is ignored #1239

pierrezimmermannbam opened this issue Nov 23, 2022 · 3 comments · Fixed by #1641

Comments

@pierrezimmermannbam
Copy link
Collaborator

Describe the bug

It is possible to change the value of a TextInput that has a maxLength prop. The following test fails for instance :

test('it should not allow to write a text longer than maxlength in a text input', () => {
  const TestComponent = () => {
    const [value, setValue] = useState('');

    return (
      <RNTextInput placeholder="placeholder" maxLength={1} onChangeText={setValue} value={value} />
    );
  };

  render(<TestComponent />);

  fireEvent.changeText(screen.getByPlaceholderText('placeholder'), 'text');

  screen.debug();
  expect(screen.queryByDisplayValue('text')).toBeFalsy();

});

Expected behavior

I'd expect that only the substring of length equal to maxlength is set as value.

Regarding the implementation I'm not sure though if this should be done by fireEvent because it just calls props and we'd have to check what the event is and have special checks in that case so maybe it's something that should be done once we have an implementation of userEvent.type. So actually I'm saying this is not really a bug but rather a use case that userEvent.type should support

@mdjastrzebski
Copy link
Member

@pierrezimmermannbam that would fall under environment simulation category. I'm not sure whether this is worth adding since this feature would simulate RN env for test, while not really guaranteeing that RN will behave the same. If this is something that concerns you you can do it, however as part of the research please analyse how real RN apps behave regarding this prop under iOS and Android. Atm the right place would be fireEvent implementation.

@mdjastrzebski
Copy link
Member

@pierrezimmermannbam Would you like to proceed with this in the near future, or should I close it as not urgent/won't fix?

@pierrezimmermannbam
Copy link
Collaborator Author

It's not a priority really we can close this for now

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

Successfully merging a pull request may close this issue.

2 participants