2024-04-02 15:33:00 +02:00
|
|
|
import {Autocomplete, TextField} from "@mui/material";
|
|
|
|
import useAsyncSearch from "../hooks/async-search";
|
|
|
|
|
|
|
|
|
|
|
|
export default function SearchField(props) {
|
|
|
|
|
2024-04-07 14:23:59 +02:00
|
|
|
const { onSearch, onSelect, ...other } = props;
|
2024-04-02 15:33:00 +02:00
|
|
|
|
|
|
|
const [searchString, setSearchString, results] = useAsyncSearch(props.onSearch, 3);
|
|
|
|
|
|
|
|
return <Autocomplete {...other}
|
|
|
|
options={Object.values(results ?? {})}
|
|
|
|
onChange={(e, n) => onSelect(n)}
|
|
|
|
renderInput={(params) => (
|
|
|
|
<TextField
|
|
|
|
{...params}
|
|
|
|
value={searchString}
|
|
|
|
onChange={e => setSearchString(e.target.value)}
|
|
|
|
label={"Search input"}
|
|
|
|
InputProps={{
|
|
|
|
...params.InputProps,
|
|
|
|
type: 'search',
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>;
|
|
|
|
}
|