File tree 2 files changed +28
-2
lines changed
2 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -171,8 +171,8 @@ export const getNextNativeValue = ({
171
171
}
172
172
173
173
if ( element . type === "number" ) {
174
- if ( typeof currentValue === "number " ) return Number ( derivedValue ) ;
175
- return String ( derivedValue ) ;
174
+ if ( typeof currentValue === "string " ) return String ( derivedValue ) ;
175
+ return Number ( derivedValue ) ;
176
176
}
177
177
178
178
return derivedValue ;
Original file line number Diff line number Diff line change @@ -31,6 +31,32 @@ describe("number inputs", () => {
31
31
expect ( screen . getByTestId ( "age-value" ) . textContent ) . toEqual ( "254" ) ;
32
32
} ) ;
33
33
34
+ it ( "no default value" , async ( ) => {
35
+ const TestComp = ( ) => {
36
+ const form = useForm ( {
37
+ validator : successValidator ,
38
+ } ) ;
39
+
40
+ return (
41
+ < form { ...form . getFormProps ( ) } >
42
+ < input
43
+ data-testid = "age"
44
+ { ...form . field ( "age" ) . getInputProps ( { type : "number" } ) }
45
+ />
46
+ < pre data-testid = "age-value" > { JSON . stringify ( form . value ( "age" ) ) } </ pre >
47
+ </ form >
48
+ ) ;
49
+ } ;
50
+ render ( < TestComp /> ) ;
51
+
52
+ expect ( screen . getByTestId ( "age" ) ) . not . toHaveValue ( ) ;
53
+ expect ( screen . getByTestId ( "age-value" ) . textContent ) . toEqual ( "" ) ;
54
+
55
+ await userEvent . type ( screen . getByTestId ( "age" ) , "4" ) ;
56
+ expect ( screen . getByTestId ( "age" ) ) . toHaveValue ( 4 ) ;
57
+ expect ( screen . getByTestId ( "age-value" ) . textContent ) . toEqual ( "4" ) ;
58
+ } ) ;
59
+
34
60
it ( "default values set as strings" , async ( ) => {
35
61
const TestComp = ( ) => {
36
62
const form = useForm ( {
You can’t perform that action at this time.
0 commit comments