Created
November 8, 2018 06:33
-
-
Save Razzwan/c462bb01d307aceeb4434c1a4e371ad6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import FormControl from '@material-ui/core/FormControl'; | |
import FormHelperText from '@material-ui/core/FormHelperText'; | |
import Input from '@material-ui/core/Input'; | |
import InputLabel from '@material-ui/core/InputLabel'; | |
import Select from '@material-ui/core/Select'; | |
import uniqueId from 'lodash-es/uniqueId'; | |
import * as React from 'react'; | |
import { WrappedFieldInputProps, WrappedFieldProps } from 'redux-form'; | |
const onChange = (input: WrappedFieldInputProps) => (event: React.ChangeEvent<HTMLSelectElement>) => | |
input.onChange(event.target.value); | |
export interface ISelectFieldProps extends WrappedFieldProps { | |
children: React.ComponentType; | |
} | |
export const SelectField = ({ input, meta: { touched, error }, children, ...custom }: ISelectFieldProps) => { | |
const id = uniqueId(); | |
return ( | |
<FormControl error={touched && error}> | |
<InputLabel htmlFor={id}>{'Проект'}</InputLabel> | |
<Select | |
error={touched && error} | |
{...input} | |
displayEmpty | |
input={<Input name={input.name} id={id} />} | |
onChange={onChange(input)} | |
children={children} | |
{...custom} | |
/> | |
{touched && error && <FormHelperText>{error}</FormHelperText>} | |
</FormControl> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment