-
Notifications
You must be signed in to change notification settings - Fork 46.9k
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
Buggy controlled number input on 15.5+ #10539
Comments
Just to add to this report, it looks like React is not updating the field that triggered the update event in the first place. See https://codesandbox.io/s/pj5jr090q0 for visual explanation |
Just tested it: works well with 15.4 and broken starting from 15.5. |
Jsfiddle with 15.4: https://jsfiddle.net/757p0rkt/ |
Broken in |
So I'm 99% sure it got introduced via #7359 to 15.5.0. |
@BTMPL 's code example working in 15.4.2: |
cc @nhunzaker |
People ask we web devs keep writing ui input libraries instead of using the native inputs...this, this stuff. |
I just checked, it is present in Firefox and Safari as well, so not Chrome related, but was introduced in the Chrome related PR. |
This is a duplicate of #9402. What's happening is React parses a number input's value as a number before doing a comparison check. So if One solution might be to compare the values as strings as well. |
Yup! Closing as a duplicate of #9402 |
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
The following code example works well with
text
input type, but allows inputs like012
or0012
to be entered when using thenumber
input type.The
console.log
line always runs and shows the right value, and the App state is also correct when checked with React Developer Tools. It's only that the controlled input is not being "controlled" somehow.Present with latest create react app or in this jsfiddle: https://jsfiddle.net/Lhj0j3ok/
Not present in this jsfiddle: https://jsfiddle.net/mayankshukla5031/08ecc97d/
What is the expected behavior?
Input should reflect the state, thus not allowing strings like
012
, etc. to be displayed.Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
Latest
create-react-app
:"react": "15.6.1",
"react-dom": "15.6.1",
"react-scripts": "1.0.11"
Browser: Chrome 60.0.3112.101
OS X 10.12.6
Present with latest create react app or in this jsfiddle: https://jsfiddle.net/Lhj0j3ok/
Not present in this jsfiddle: https://jsfiddle.net/mayankshukla5031/08ecc97d/
The text was updated successfully, but these errors were encountered: