-
Notifications
You must be signed in to change notification settings - Fork 47k
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
[RFC] Enabling form.reset() on controlled inputs, make value and defaultValue more transparent #8011
Comments
If you have controlled inputs you already have a sanctioned way of resetting them, using |
I disagree. It's intuitive that inputs, which already get significant treatment to normalize change event behavior, would trigger a change when a form resets. My primary motivation is, of course, to address edge cases with special inputs types in Chrome, but this also makes forms more resilient. Instead of fighting against the browser, it plays nice. |
I've updated the title. I ended up going with an alternative approach to fix Chrome's input issues for #7359, but I'd love to keep talking about this. |
It's been a long time, but I've updated the description of this issue to provide a more coherent description of my proposal. |
With the discussion in #13526, I believe this should be closed. The behavior of |
I would like to make a case for supporting
form.reset()
for controlled inputs, and to make control over value and defaultValue more direct.Background
React synchronizes the
value
attribute and thevalue
property on inputs. I believe this is for two reasons:[value="*"]
when testingform.reset
reverts an input back to it's value attribute. It also does not trigger change events, which causes input state to be out of sync with React state.There are many reasons listed in #11896 to stop syncing the value attribute, so I'll keep this issue focused on my desired outcome.
The Change
I want to be able to control the value attribute and property directly from a component, at the same time:
With this change:
value
React property directly maps to the value propertydefaultValue
React property directly maps to the value attributevalue
anddefaultValue
are configurable at the same timevalue
propertyWhy
This change creates a more controlled input, and makes it much clearer how React applies changes. More control is granted to the user. It provides away to allow props coming into a form to dictate a canonical state for the form, while still supporting native browser behavior.
Also, it means that we don't synchronize the value attribute, which would save a lot of headaches 😄.
Things to figure out
Server rendering. What property do we use? In the case, we can only send along the default value. That might be fine for most cases, but I have not thought through the edge cases.
The text was updated successfully, but these errors were encountered: