1
1
import TextField , { TextFieldProps } from "@material-ui/core/TextField"
2
- import { FormikLike } from "../../util/ formik"
2
+ import { FormikContextType as FormikLike } from "formik"
3
3
import React from "react"
4
4
import { PasswordField } from "./PasswordField"
5
- import { FormFieldProps } from "./types"
5
+
6
+ /**
7
+ * FormFieldProps are required props for creating form fields using a factory.
8
+ */
9
+ export interface FormFieldProps < T > {
10
+ /**
11
+ * form is a reference to a form or subform and is used to compute common
12
+ * states such as error and helper text
13
+ */
14
+ form : FormikLike < T >
15
+ /**
16
+ * formFieldName is a field name associated with the form schema.
17
+ */
18
+ formFieldName : keyof T
19
+ }
20
+
6
21
7
22
/**
8
23
* FormTextFieldProps extends form-related MUI TextFieldProps with Formik
@@ -12,31 +27,31 @@ import { FormFieldProps } from "./types"
12
27
*/
13
28
export interface FormTextFieldProps < T >
14
29
extends Pick <
15
- TextFieldProps ,
16
- | "autoComplete"
17
- | "autoFocus"
18
- | "children"
19
- | "className"
20
- | "disabled"
21
- | "fullWidth"
22
- | "helperText"
23
- | "id"
24
- | "InputLabelProps"
25
- | "InputProps"
26
- | "inputProps"
27
- | "label"
28
- | "margin"
29
- | "multiline"
30
- | "onChange"
31
- | "placeholder"
32
- | "required"
33
- | "rows"
34
- | "select"
35
- | "SelectProps"
36
- | "style"
37
- | "type"
38
- > ,
39
- FormFieldProps < T > {
30
+ TextFieldProps ,
31
+ | "autoComplete"
32
+ | "autoFocus"
33
+ | "children"
34
+ | "className"
35
+ | "disabled"
36
+ | "fullWidth"
37
+ | "helperText"
38
+ | "id"
39
+ | "InputLabelProps"
40
+ | "InputProps"
41
+ | "inputProps"
42
+ | "label"
43
+ | "margin"
44
+ | "multiline"
45
+ | "onChange"
46
+ | "placeholder"
47
+ | "required"
48
+ | "rows"
49
+ | "select"
50
+ | "SelectProps"
51
+ | "style"
52
+ | "type"
53
+ > ,
54
+ FormFieldProps < T > {
40
55
/**
41
56
* eventTransform is an optional transformer on the event data before it is
42
57
* processed by formik.
@@ -105,9 +120,9 @@ export const formTextFieldFactory = <T,>(): React.FC<FormTextFieldProps<T>> => {
105
120
} ) => {
106
121
const isError = form . touched [ formFieldName ] && Boolean ( form . errors [ formFieldName ] )
107
122
108
- // Conversion to a string primitive is necessary as formFieldName is an in
109
- // indexable type such as a string, number or enum .
110
- const fieldId = FormikLike . getFieldId < T > ( form , String ( formFieldName ) )
123
+ // TODO: When we need to bring back FormikLike / subforms, use
124
+ // the `FormikLike.getFieldId` helper .
125
+ const fieldId = String ( formFieldName )
111
126
112
127
const Component = isPassword ? PasswordField : TextField
113
128
const inputType = isPassword ? undefined : type
0 commit comments