fix(type=number): Don't parseFloat empty value strings, they NaN #1136
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
#1100 added automatic number parsing of
<input type="number">
fields but if the field is empty it currently appliesparseFloat
to an empty string, which producesNaN
which could be argued either way as right or wrong, but this has the consequence of making the<input>
warn in Google Chrome with:This happens on every re-render, once that field has been touched. Using
undefined
also invokes the warning, the only thing that doesn't is the default empty string or a string that is a valid number.Because of #1089 I can't create a JSBin to reproduce, but here's some code:
If it's too awkward now the value might be an empty string or a parsed number, I think removing the parsing number behavior altogether is probably the right call. Then the behavior is the same as the browser. Especially because
parseFloat
has known quirks that may causes issues in browsers that don't actually restrict you from typing non-number characters in the input (like Chrome does). e.g. they type'1-dal@41'
andparseFloat('1-dal@41') === 1