You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Do you want to request a feature or report a bug?
bug What is the current behavior?
<input type="number"> fields do not call onChange, and ignore their controlled value if text is entered into them. Upon a number being entered, they start to use onChange correctly.
With this code, no state change occurs, so the controlled input does not receive a new value. React doesn't know to render again. What if instead, you did something like this:
I'm running into the same issue as well, with both examples.
I think the problem he's describing is that when you type in non-numeric characters in <input type="number"/>, the input field is rendering with the characters being typed in, but the onChange function is not being called. onChange seems to only get called if the user types in a number
In chrome, you can try typing characters like "e", "E", "-" etc. You can see the characters being added to the input, but onChange is not called. It seems in Firefox and Edge, the inputs are not restricted at all, so any characters will trigger this issue.
Chrome 76.0.3809.100 64bit
Firefox 68.0.2 64bit
Reacted by CY, Shibasis Patnaik, andoks, jgarnie, Jonathan, Vitalii Dvorian, rudolphthecat, Guilherme Avanci, Stefan, Thomas Faller and 1 more
Now that I look at it again, it looks like input.value (from the dom node) will be an empty string if the value in the input isn't a valid number. Since typing in just "e" is invalid, input.value doesn't change hence why onChange is not triggered. I'm guessing this is intentional
Ah right. If I remember correctly, Chrome does not emit change events for invalid values. Characters like e and - are valid text entry for number inputs because they are associated with scientific notation and negative numbers.
I believe we've hit this in the past, and there isn't anything we can do. For complete and utter control of the text, using an input with a type of text yields the best results.
Still, I can check to make sure this is consistent with what we've hit in the past before closing this issue.
I have resorted to using a text field indeed, which was a nice easy workaround; perhaps this could be reflected somewhere in the docs though, just to save others time and heartache 🤡
@CluEleSsUK AFAIK there are also some issues with number input on Android systems (not sure if they are still present, but definitely there were issues in the past). So it totally makes sense to be aware of different nuances in order to save nerves during development 🙂
Especially frustrating when wanting to type a float into an input without a leading zero: .15 versus 0.15, the latter firing onChange, the former does not
I found this issue while searching online and it doesn't include a solution.
Do not use type="number". It has too many inherent problems (including this one) that are native to the HTML spec and cannot be fixed. Use type="text" inputmode="numeric" instead, or a variation.
Activity
nhunzaker commentedon Aug 23, 2019
Hey @CluEleSsUK, thanks for filing this!
I had a question about your example:
With this code, no state change occurs, so the controlled input does not receive a new value. React doesn't know to render again. What if instead, you did something like this:
I made an example of that here:
https://codesandbox.io/s/new-darkness-wzgnt
If you follow this pattern, does the problem persist for you? If so, could you share what browser and browser version you are using?
canytra commentedon Aug 23, 2019
I'm running into the same issue as well, with both examples.
I think the problem he's describing is that when you type in non-numeric characters in
<input type="number"/>, the input field is rendering with the characters being typed in, but theonChangefunction is not being called.onChangeseems to only get called if the user types in a numberIn chrome, you can try typing characters like "e", "E", "-" etc. You can see the characters being added to the input, but
onChangeis not called. It seems in Firefox and Edge, the inputs are not restricted at all, so any characters will trigger this issue.Chrome 76.0.3809.100 64bit
Firefox 68.0.2 64bit
canytra commentedon Aug 24, 2019
Now that I look at it again, it looks like
input.value(from the dom node) will be an empty string if the value in the input isn't a valid number. Since typing in just "e" is invalid,input.valuedoesn't change hence whyonChangeis not triggered. I'm guessing this is intentionalCluEleSsUK commentedon Aug 24, 2019
Oops yes my example was a little buggy; I still get the same behaviour on your example however. I am using Firefox developer edition 69.0b16
nhunzaker commentedon Aug 25, 2019
Ah right. If I remember correctly, Chrome does not emit change events for invalid values. Characters like
eand-are valid text entry for number inputs because they are associated with scientific notation and negative numbers.I believe we've hit this in the past, and there isn't anything we can do. For complete and utter control of the text, using an input with a type of
textyields the best results.Still, I can check to make sure this is consistent with what we've hit in the past before closing this issue.
CluEleSsUK commentedon Aug 25, 2019
I have resorted to using a text field indeed, which was a nice easy workaround; perhaps this could be reflected somewhere in the docs though, just to save others time and heartache 🤡
miraage commentedon Aug 26, 2019
@CluEleSsUK Usually reading the docs (not just React, but about HTML/JS too) helps to avoid such situations.
CluEleSsUK commentedon Aug 26, 2019
Thanks for your input @miraage
miraage commentedon Aug 26, 2019
@CluEleSsUK AFAIK there are also some issues with number input on Android systems (not sure if they are still present, but definitely there were issues in the past). So it totally makes sense to be aware of different nuances in order to save nerves during development 🙂
threepointone commentedon Aug 26, 2019
There doesn’t seem to be much react can do here. I’m going to close this issue, but feel free to discuss
fardad-dev commentedon Jul 11, 2020
I solved this issue by type="tel"
softwarenacho commentedon Oct 7, 2021
this should be in the documentation 😄 saved me after hours of tries
aelmi03 commentedon Jan 29, 2022
Thanks for sharing the solution! Saved me a lot of frustration.
shmup commentedon Feb 14, 2023
Especially frustrating when wanting to type a float into an input without a leading zero:
.15versus0.15, the latter firing onChange, the former does notkerematam commentedon Mar 17, 2023
Warning for the ones who are about to implement this:
It is against a11y rules! Number input should be number input.
sam-k commentedon Aug 17, 2025
I found this issue while searching online and it doesn't include a solution.
Do not use
type="number". It has too many inherent problems (including this one) that are native to the HTML spec and cannot be fixed. Usetype="text" inputmode="numeric"instead, or a variation.Read more here: https://technology.blog.gov.uk/2020/02/24/why-the-gov-uk-design-system-team-changed-the-input-type-for-numbers/