-
Notifications
You must be signed in to change notification settings - Fork 33
/
Select.tsx
43 lines (36 loc) · 1.14 KB
/
Select.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import * as React from 'react';
import Select from '@material-ui/core/Select';
import FormControl from '@material-ui/core/FormControl';
import InputLabel from '@material-ui/core/InputLabel';
import FormHelperText from '@material-ui/core/FormHelperText';
import {FormControlProps} from '@material-ui/core/FormControl';
import {FieldRenderProps} from 'react-final-form';
interface FormHelperTextWrapperProps extends FieldRenderProps {
label: string,
formControlProps: FormControlProps,
}
const FormHelperTextWrapper: React.SFC<FormHelperTextWrapperProps> = ({
input: {name, value, onChange, ...restInput},
meta,
label,
formControlProps,
...rest
}) => {
const showError = ((meta.submitError && !meta.dirtySinceLastSubmit) || meta.error) && meta.touched;
return (
<FormControl {...formControlProps} error={showError}>
<InputLabel htmlFor={name}>{label}</InputLabel>
<Select
{...rest}
name={name}
onChange={onChange}
inputProps={restInput}
value={value}
/>
{showError &&
<FormHelperText>{meta.error || meta.submitError}</FormHelperText>
}
</FormControl>
);
};
export default FormHelperTextWrapper;