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

[React 19] Controlled number input does not update defaultValue when value prop has changed #29862

Open
BrendonSled opened this issue Jun 11, 2024 · 4 comments
Labels

Comments

@BrendonSled
Copy link

Summary

Controlled inputs with the type=number are not setting the defaultValue when the value state is altered. This causes the state and value to become out of sync when a form is reset (for instance after a form action is sent).

Screenshot 2024-06-11 at 1 12 08 PM

https://codesandbox.io/p/github/BrendonSled/react-19-controlled-input-number-bug/

@Sunilverma99
Copy link

#29862
The issue arises because the useEffect hook depends on both value1 and value2, causing the value not to update properly. By removing the dependencies on value1 and value2, the component functions correctly.
Screenshot 2024-06-13 114347
Screenshot 2024-06-13 114318

@Musaeeb-Zahir
Copy link

Hi

@BrendonSled
Copy link
Author

@Sunilverma99 you're inspecting the wrong values there. This issue is specifically around the defaultValue that is set so when a form is reset the values are not correct. If you inspect the element you can get a better example of what is happening here. All other input types will have the html attributes change except type=number

Screenshot 2024-06-11 at 1 01 17 PM

@BrendonSled
Copy link
Author

https://codesandbox.io/p/github/BrendonSled/react-19-controlled-input-number-bug/new-example

This might be a better example of the exact issue I'm facing. If you input hit the enter key while focused in the number input the field value will be erased on the form submit even though the state is still the old value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants