@@ -33,7 +33,7 @@ export interface TextFieldProps<
3333> extends UITextFieldProps {
3434 name : TName
3535 /** HTML type attribute, defaults to text */
36- type ?: string
36+ type ?: 'text' | 'password'
3737 /** Will default to name if not provided */
3838 label ?: string
3939 /**
@@ -92,17 +92,9 @@ export function TextField<
9292 )
9393}
9494
95- function numberToInputValue ( value : number ) {
96- // could add `|| value === 0`, but that means when the value is 0, we always
97- // show an empty string, which is weird, and doubly bad because then the
98- // browser apparently fails to validate it against minimum (if one is
99- // provided). I found it let me submit instance create with 0 CPUs.
100- return isNaN ( value ) ? '' : value . toString ( )
101- }
102-
10395/**
10496 * Primarily exists for `TextField`, but we occasionally also need a plain field
105- * without a label on it. Note special handling of `type="number"`.
97+ * without a label on it.
10698 *
10799 * Note that `id` is an allowed prop, unlike in `TextField`, where it is always
108100 * generated from `name`. This is because we need to pass the generated ID in
@@ -131,7 +123,7 @@ export const TextFieldInner = <
131123 name = { name }
132124 control = { control }
133125 rules = { { required, validate } }
134- render = { ( { field : { onChange, value , ...fieldRest } , fieldState : { error } } ) => {
126+ render = { ( { field : { onChange, ...fieldRest } , fieldState : { error } } ) => {
135127 return (
136128 < >
137129 < UITextField
@@ -143,32 +135,9 @@ export const TextFieldInner = <
143135 [ `${ id } -help-text` ] : ! ! tooltipText ,
144136 } ) }
145137 aria-describedby = { tooltipText ? `${ id } -label-tip` : undefined }
146- // note special handling for number fields, which produce a number
147- // for the calling code despite the actual input value necessarily
148- // being a string.
149138 onChange = { ( e ) => {
150- if ( transform ) {
151- onChange ( transform ( e . target . value ) )
152- return
153- }
154- if ( type === 'number' ) {
155- if ( e . target . value . trim ( ) === '' ) {
156- onChange ( 0 )
157- } else if ( ! isNaN ( e . target . valueAsNumber ) ) {
158- onChange ( e . target . valueAsNumber )
159- }
160- // otherwise ignore the input. this means, for example, typing
161- // letters does nothing. If we instead said take anything
162- // that's NaN and fall back to 0, typing a letter would reset
163- // the field to 0, which is silly. Browsers are supposed to
164- // ignore non-numeric input for you anyway, but Firefox does
165- // not.
166- return
167- }
168-
169- onChange ( e . target . value )
139+ onChange ( transform ? transform ( e . target . value ) : e . target . value )
170140 } }
171- value = { type === 'number' ? numberToInputValue ( value ) : value }
172141 { ...fieldRest }
173142 { ...props }
174143 />
0 commit comments