selector.select

This commit is contained in:
ari committed 2022-06-15 10:43:14 -04:00
1 parent 596c3363e7
commit 0fc3ea6146
4 files changed
+155 -65

No files matched your search

+35 -22
View File
@@ -1,11 +1,15 @@
import TextField from "@mui/material/TextField";
import Autocomplete from "@mui/material/Autocomplete";
import { ReactNode } from "react";
export interface InputAutoTextProps {
label: string;
value: string;
className?: string;
options?: string[];
error?: string;
required?: boolean;
endAdornment?: ReactNode;
onChange: (v: string) => void;
}
export default function InputAutoText({
@@ -13,28 +17,37 @@ export default function InputAutoText({
label,
options = [],
onChange,
className,
required,
endAdornment,
error,
}: InputAutoTextProps) {
return <Autocomplete
freeSolo
value={value}
options={options}
onChange={(_e, v) => onChange(
v === null ? "" : v
)}
renderInput={params => <TextField
{...params}
variant="filled"
label={label}
error={error !== undefined}
helperText={error}
onChange={e => {
e.preventDefault();
onChange(
e.target.value
)
}}
/>}
/>
console.log(options);
return (
<Autocomplete
freeSolo
className={className}
value={value}
options={options}
onChange={(_e, v) => onChange(v === null ? "" : v)}
renderInput={(params) => (
<TextField
{...params}
required={required}
variant="filled"
label={label}
error={error !== undefined}
helperText={error}
fullWidth
InputProps={{
endAdornment,
}}
onChange={(e) => {
e.preventDefault();
onChange(e.target.value);
}}
/>
)}
/>
);
}