-
Notifications
You must be signed in to change notification settings - Fork 47.7k
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
input[type='number'] event.target.value changes to empty string when . or , pressed and onChange not emitted when . and , used #13752
Comments
Tried to reproduce with the latest version of React(16.5.2) https://codesandbox.io/s/53rm6jjx7k |
Isn't it a matter of localization? (maybe change the |
I'm not sure if it's a matter of localization. I'll check that out. For now I've made a video showcasing the problem. additional info: |
lang attr didn't help |
This is not a bug in React but the way native HTML input type number parses the floating numbers. The behavior in React input is similar to the behavior in the non-react input field. Refer this example to replicate the same in non-react input field by typing a valid number and then You will notice once you input one of the above wrong inputs the change event listener is not triggered. Here is why this happens?
Click here for HTML spec reference Valid floating numbers
Invalid floating numbers
When the input number does not pass the validation it throws error and doesn't trigger the change listener. Refer the above link of the HTML spec. How to solve this on UI? |
@haldarmahesh indeed this is exactly how native |
It's a Chrome bug. For a workaround you can check my codepen: https://codepen.io/whazam/pen/oOWxPK |
This isn't a bug in React, or Chromium either. While this behavior is sub-optimal, it's behaving as expected. Here's what the HTML spec defines:
Chromium is simply implementing the HTML spec, and React is accessing the input's value via the input's value attribute. Here's a more in-depth explanation, as well as a potential fix. |
Do you want to request a feature or report a bug?
bug
What is the current behavior?
onChange event changes value of an input to an empty string when . or , is pressed. Additionally it seems like it doesn't fire onChange after the dot and comma (example 1.234,000) at all
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have dependencies other than React. Paste the link to your JSFiddle (https://jsfiddle.net/Luktwrdm/) or CodeSandbox (https://codesandbox.io/s/new) example below:
https://codesandbox.io/s/7ox8qx2mn1
What is the expected behavior?
value stays as an Integer or as seen by the user 1. should be 1. and not "". Should fire onChange.
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
React 16 +, Chrome, No
The text was updated successfully, but these errors were encountered: