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
Feature/number field #1014
Merged
Merged
Feature/number field #1014
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Codecov Report
@@ Coverage Diff @@
## main #1014 +/- ##
==========================================
+ Coverage 89.17% 89.29% +0.12%
==========================================
Files 257 259 +2
Lines 7225 7316 +91
Branches 1862 1887 +25
==========================================
+ Hits 6443 6533 +90
+ Misses 700 699 -1
- Partials 82 84 +2
Continue to review full report at Codecov.
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
This PR introduces a new hook for the
@react-md/form
package to work with<input type="number">
due to all the browser behavior weirdness. The new hook is nameduseNumberField
and can be used with aTextField
orTextFieldWithMessage
component where the first value in the returned array is the currentnumber
value of the input while the second value is an object of props to pass to theTextField
orTextFieldWithMessage
components.Some things to note:
number
value will beundefined
ONLY if nodefaultValue
was provided to the hooknumber
value can be updated only on blur instead of on change if neededmin
andmax
values (configurable)0
suseTextField
hook with a few more options and a different"number-recommended"
validateOnChange
valueSimple Number Field Example
Number Field with Validation
General "Fixes"
The field will show an error and maintain the floating label if the user types an invalid number that the browser doesn't prevent since the browser will prevent letters from being typed, but it allows some of these invalid strings:
--0
3242-
3-0
++1
Video example here
This was actually pretty difficult/annoying to fix since once the field goes into an "invalid" state, it doesn't report change events and reports the value as the empty string. This should be fixed going forward.
Closes #280