-
Notifications
You must be signed in to change notification settings - Fork 16
Use NumberField instead of TextField for inputs of type number
#1812
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
Closed
Conversation
This file contains hidden or 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
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
just-be-dev
commented
Dec 7, 2023
| import { ErrorMessage } from './ErrorMessage' | ||
|
|
||
| export interface TextFieldProps< | ||
| Type, |
Contributor
Author
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't actually like this change, it's a bit of a contagion. It's used to aid in typing the transform but I suspect there might be a better way to do this.
Contributor
Author
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.
Changes
Replaces all instances of
TextFieldwheretype=numberwithNumberField.Background
When investigating the fix for #1438, I began investigating our ability to do transformations on text input before form submissions.
react-hook-form's docs have a section on transformation and parsing in which they recommend either creating a high order controller component that receives atransformfunction that can operate viavalue/onChangeor by usingregisterprops likevalueAsDate,valueAsNumberorsetValueAs. The latter seems closer to what we'd actually want to do, but we're not actually usingregister.registerhangs off of the form object returned viauseFormand refactoring our inputs to use that approach would be a larger effort than seems warranted for just this functionality. TheControllercomponent which we're using to define our components has arulesprop that takes arguments intended forregisterbut it explicitly omits the value transformation props . I timed boxed some explorations in seeing if I could have therulesprop resolve the value transformation fields upstream but wasn't able to get to a satisfactory outcome in the time allotted so I decided just to try my hand at a user land implementation.After that investigation I noticed we were actually doing some userland transformation in the
TextFieldcomponent. It's specifically around the special handling of numbers though, which seemed odd to me given that we have a dedicatedNumberFieldcomponent.console/app/components/form/fields/TextField.tsx
Lines 146 to 163 in ae8218d
The presence of this normalization logic for numbers makes the implementation of a transformation slightly more complicated than it needs to be and (to me) points to a larger need for changes. Thus I decided to take the first step of untangling the number logic from the
TextFieldby specifically relegating that to theNumberFieldRemaining work
NumberFieldhas the same input handling logic as was present inTextFieldTextField