-
Notifications
You must be signed in to change notification settings - Fork 47.6k
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
Keep value of controlled number fields upon action #30737
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
This makes sense to me but maybe needs another pair of eyes. I'm not sure this is exhaustive since you can trigger actions and resets in arbitrary way - such as based on a different keystroke. Ideally maybe it would sync it right before resetting. |
I don't really like doing it in keypress, that seems too clever given that it's not exhaustive… should we do it in the |
Working on another solution with more changes |
Opened a new PR with different solution (which I think is more correct) - #30752 |
Closing this, as there is a more suitable solution in #30752 |
Summary
Currently, React changes the defaultValue for number fields not on every change, but on blur. The reasons are described in issue #7253.
Now this bug is not reproducible in Chrome. Just to be sure, I checked that it was fixed specifically in Chrome, and not with some React update (I ran React v15.2 in modern Chrome and there were no issues from the task there either).
I extended the
EventPlugin
, making the replacement ofdefaultValue
not only on blur, but also on submit (since you can press Enter without leaving the field and the form will be submitted). But I did it specifically on thekeypress
event, so that it works before reset and on the submit itself without a submitter (this is, for example, when callingrequestSubmit()
).Added a "
force
" option insetDefaultValue
, because a numeric field can be in focus (and on submit, the value needs to be changed always).I honestly tried to cover this with tests, but couldn't find a way to trigger submit by simulating a key press...
Fixes #29862
Closes #29862
How did you test this change?
Before fix:
react_number_on_action_before.mp4
After fix:
react_number_on_action_after.mp4