@@ -26,31 +26,31 @@ export interface FormFieldProps<T> {
26
26
*/
27
27
export interface FormTextFieldProps < T >
28
28
extends Pick <
29
- TextFieldProps ,
30
- | "autoComplete"
31
- | "autoFocus"
32
- | "children"
33
- | "className"
34
- | "disabled"
35
- | "fullWidth"
36
- | "helperText"
37
- | "id"
38
- | "InputLabelProps"
39
- | "InputProps"
40
- | "inputProps"
41
- | "label"
42
- | "margin"
43
- | "multiline"
44
- | "onChange"
45
- | "placeholder"
46
- | "required"
47
- | "rows"
48
- | "select"
49
- | "SelectProps"
50
- | "style"
51
- | "type"
52
- > ,
53
- FormFieldProps < T > {
29
+ TextFieldProps ,
30
+ | "autoComplete"
31
+ | "autoFocus"
32
+ | "children"
33
+ | "className"
34
+ | "disabled"
35
+ | "fullWidth"
36
+ | "helperText"
37
+ | "id"
38
+ | "InputLabelProps"
39
+ | "InputProps"
40
+ | "inputProps"
41
+ | "label"
42
+ | "margin"
43
+ | "multiline"
44
+ | "onChange"
45
+ | "placeholder"
46
+ | "required"
47
+ | "rows"
48
+ | "select"
49
+ | "SelectProps"
50
+ | "style"
51
+ | "type"
52
+ > ,
53
+ FormFieldProps < T > {
54
54
/**
55
55
* eventTransform is an optional transformer on the event data before it is
56
56
* processed by formik.
@@ -104,67 +104,61 @@ export interface FormTextFieldProps<T>
104
104
* )
105
105
* }
106
106
*/
107
- export const formTextFieldFactory = < T , > ( ) : React . FC < FormTextFieldProps < T > > => {
108
- const component : React . FC < FormTextFieldProps < T > > = ( {
109
- children,
110
- disabled,
111
- displayValueOverride,
112
- eventTransform,
113
- form,
114
- formFieldName,
115
- helperText,
116
- isPassword = false ,
117
- InputProps,
118
- onChange,
119
- type,
120
- variant = "outlined" ,
121
- ...rest
122
- } ) => {
123
- const isError = form . touched [ formFieldName ] && Boolean ( form . errors [ formFieldName ] )
107
+ export const FormTextField = < T , > ( {
108
+ children,
109
+ disabled,
110
+ displayValueOverride,
111
+ eventTransform,
112
+ form,
113
+ formFieldName,
114
+ helperText,
115
+ isPassword = false ,
116
+ InputProps,
117
+ onChange,
118
+ type,
119
+ variant = "outlined" ,
120
+ ...rest
121
+ } : FormTextFieldProps < T > ) : React . ReactElement => {
122
+ const isError = form . touched [ formFieldName ] && Boolean ( form . errors [ formFieldName ] )
124
123
125
- // Conversion to a string primitive is necessary as formFieldName is an in
126
- // indexable type such as a string, number or enum.
127
- const fieldId = String ( formFieldName )
124
+ // Conversion to a string primitive is necessary as formFieldName is an in
125
+ // indexable type such as a string, number or enum.
126
+ const fieldId = String ( formFieldName )
128
127
129
- const Component = isPassword ? PasswordField : TextField
130
- const inputType = isPassword ? undefined : type
128
+ const Component = isPassword ? PasswordField : TextField
129
+ const inputType = isPassword ? undefined : type
131
130
132
- return (
133
- < Component
134
- { ...rest }
135
- variant = { variant }
136
- disabled = { disabled || form . isSubmitting }
137
- error = { isError }
138
- helperText = { isError ? form . errors [ formFieldName ] : helperText }
139
- id = { fieldId }
140
- InputProps = { isPassword ? undefined : InputProps }
141
- name = { fieldId }
142
- onBlur = { form . handleBlur }
143
- onChange = { ( e ) => {
144
- if ( typeof onChange !== "undefined" ) {
145
- onChange ( e )
146
- }
131
+ return (
132
+ < Component
133
+ { ...rest }
134
+ variant = { variant }
135
+ disabled = { disabled || form . isSubmitting }
136
+ error = { isError }
137
+ helperText = { isError ? form . errors [ formFieldName ] : helperText }
138
+ id = { fieldId }
139
+ InputProps = { isPassword ? undefined : InputProps }
140
+ name = { fieldId }
141
+ onBlur = { form . handleBlur }
142
+ onChange = { ( e ) => {
143
+ if ( typeof onChange !== "undefined" ) {
144
+ onChange ( e )
145
+ }
147
146
148
- const event = e
149
- if ( typeof eventTransform !== "undefined" ) {
150
- // TODO(Grey): Asserting the type as a string here is not quite
151
- // right in that when an input is of type="number", the value will
152
- // be a number. Type asserting is better than conversion for this
153
- // reason, but perhaps there's a better way to do this without any
154
- // assertions.
155
- event . target . value = eventTransform ( e . target . value ) as string
156
- }
157
- form . handleChange ( event )
158
- } }
159
- type = { inputType }
160
- value = { displayValueOverride || form . values [ formFieldName ] }
161
- >
162
- { children }
163
- </ Component >
164
- )
165
- }
166
-
167
- // Required when using an anonymous factory function
168
- component . displayName = "FormTextField"
169
- return component
170
- }
147
+ const event = e
148
+ if ( typeof eventTransform !== "undefined" ) {
149
+ // TODO(Grey): Asserting the type as a string here is not quite
150
+ // right in that when an input is of type="number", the value will
151
+ // be a number. Type asserting is better than conversion for this
152
+ // reason, but perhaps there's a better way to do this without any
153
+ // assertions.
154
+ event . target . value = eventTransform ( e . target . value ) as string
155
+ }
156
+ form . handleChange ( event )
157
+ } }
158
+ type = { inputType }
159
+ value = { displayValueOverride || form . values [ formFieldName ] }
160
+ >
161
+ { children }
162
+ </ Component >
163
+ )
164
+ }
0 commit comments