-
Notifications
You must be signed in to change notification settings - Fork 12
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
Use NumberField
instead of TextField
for inputs of type number
#1812
Closed
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
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
zephraph
commented
Dec 7, 2023
@@ -28,12 +28,13 @@ import { capitalize } from '@oxide/util' | |||
import { ErrorMessage } from './ErrorMessage' | |||
|
|||
export interface TextFieldProps< | |||
Type, |
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.
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
TextField
wheretype=number
withNumberField
.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 atransform
function that can operate viavalue
/onChange
or by usingregister
props likevalueAsDate
,valueAsNumber
orsetValueAs
. The latter seems closer to what we'd actually want to do, but we're not actually usingregister
.register
hangs off of the form object returned viauseForm
and refactoring our inputs to use that approach would be a larger effort than seems warranted for just this functionality. TheController
component which we're using to define our components has arules
prop that takes arguments intended forregister
but it explicitly omits the value transformation props . I timed boxed some explorations in seeing if I could have therules
prop 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
TextField
component. It's specifically around the special handling of numbers though, which seemed odd to me given that we have a dedicatedNumberField
component.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
TextField
by specifically relegating that to theNumberField
Remaining work
NumberField
has the same input handling logic as was present inTextField
TextField