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

HTML5 number input uncontrolled mode issues when changing defaultValue #7507

Closed
quantizor opened this issue Aug 15, 2016 · 5 comments
Closed

Comments

@quantizor
Copy link
Contributor

Do you want to request a feature or report a bug?

bug

What is the current behavior?

Providing a defaultValue to an HTML5 number input causes the element to enter into some sort of semi-controlled mode. Changing the defaultValue should be a noop after the element has been mounted, but it seems to set a property in the element and break the behavior of the uncontrolled component.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem.

See this fiddle and try to enter 1e8: http://codepen.io/3lux/pen/yJkWoj

What is the expected behavior?

1e8 should show up in the input box; since some DOM property is being changed when the provided defaultValue is changed, I think the DOM is trying to programmatically set the input to an interim value that's not a real number, like 1e and then wipes it out and resets to an empty string, which is caught in the onChange handler and persisted back to the defaultValue, effectively losing the input.

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?

Latest React, latest Chrome

@quantizor quantizor changed the title HTML5 number input uncontrolled mode issues with changing defaultValue HTML5 number input uncontrolled mode issues when changing defaultValue Aug 15, 2016
@nhunzaker
Copy link
Contributor

I believe this is the same issue as #7253, it happens because defaultValue always gets reassigned on change:

https://github.com/facebook/react/blob/master/src/renderers/dom/client/wrappers/ReactDOMInput.js#L217

Invoked in the handleChange callback for inputs here:

https://github.com/facebook/react/blob/master/src/renderers/dom/client/wrappers/ReactDOMInput.js#L284

uncontrolled

@aweary
Copy link
Contributor

aweary commented Aug 16, 2016

Yupp, same root cause as #7253. This isn't specific to defaultValue, you'd have the same issue if you used value. https://jsfiddle.net/Lqgh8v7a/. I'm going to close this, but feel free to subscribe to #7253 for updates on this 👍

@aweary aweary closed this as completed Aug 16, 2016
@quantizor
Copy link
Contributor Author

Why are you closing it? You just admitted it's a legitimate bug.

@aweary
Copy link
Contributor

aweary commented Aug 16, 2016

I'm not closing it because it's not a bug, I'm closing it because it's an issue we're already tracking in #7253. Having multiple issues open for variations of a root issue only serves to fragment discussion (see #7297 for another example #7253)

It's not that we're ignoring it, just trying to keep our issues organized 😄 you can subscribe to #7253 to get updates on any progress made. @nhunzaker has some PRs open that seem to address this, so it might just be a matter of getting those reviewed 👍

@quantizor
Copy link
Contributor Author

Okay, thanks.

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

No branches or pull requests

3 participants