Skip to content

Instantly share code, notes, and snippets.

@Razzwan
Created November 8, 2018 06:33
Show Gist options
  • Save Razzwan/c462bb01d307aceeb4434c1a4e371ad6 to your computer and use it in GitHub Desktop.
Save Razzwan/c462bb01d307aceeb4434c1a4e371ad6 to your computer and use it in GitHub Desktop.
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