import React from "react";
import { FormControl, FormHelperText, InputLabel, Select } from "material-ui";
export const SelectField = ({
input: { name, onChange, value, ...restInput },
meta,
children,
label,
fullWidth,
margin,
InputLabelProps,
...rest
}) => (
<FormControl fullWidth={fullWidth} margin={margin}>
{label && <InputLabel error={meta.error && meta.touched} {...InputLabelProps}>{label}</InputLabel>}
<Select
{...rest}
name={name}
error={meta.error && meta.touched}
inputProps={restInput}
value={value}
onChange={onChange}
>
{children}
</Select>
{meta.error &&
meta.touched && (
<FormHelperText error={true}>{meta.error}</FormHelperText>
)}
</FormControl>
);
Demo code: https://codesandbox.io/s/kkp59xr047
No comments:
Post a Comment