-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
[InputGroup] Displayed value does not match value of 'value' prop #4375
Comments
I made some changes to the input value state logic in v3.34.0 in order to work around issues like #4298, which may have caused this issue to occur. However: onChange={onChange={(e) => {
e.target.value = e.target.value.replace(/[^0-9]/g, '').substr(0, 10);
onChange(e);
}} Editing the DOM directly like that is not a good pattern in React, especially if you're also setting the |
Right. The reason why I wrote the onChange function that way was because I am passing formik.handleChange as the onChange prop in the parent component. However, this issue still persists if I write the code in the following way: onChange={(e) => {
onChange(e.target.value.replace(/[^0-9]/g, '').substr(0, 10));
}} Parent: onChange={(val) => formik.setFieldValue('phone', val)} |
Is it possible to demonstrate the problem using a code sandbox (linked in the issue template)? |
Sure Thing. The incorrect behavior actually exists just using a useState hook. I should not be able to enter non-number characters, or more than 10 numbers. The value state variable follows the correct behavior, but the input does not. Note that if you change the @blueprintjs/core version in package.json to 3.33.0 the desired behavior is achieved. |
Environment
Steps to reproduce
My onChange function is designed to limit the entered characters to only 10 numbers:
Actual behavior
Any non-number characters and characters after length 10 are properly not stored in 'value' but still display in the input field.
Expected behavior
The displayed text in the input field should match the value of the 'value' prop. This works in @blueprintjs/core 3.33.0.
The text was updated successfully, but these errors were encountered: