import React, { useRef } from 'react'; import { TextField, InputAdornment, IconButton, TextFieldProps, } from '@material-ui/core'; import { Search as SearchIcon, Close as CloseIcon } from '@material-ui/icons'; export type SearchInputProps = TextFieldProps & { onResetValue?: () => void; }; function SearchInput({ value, onResetValue, ...rest }: SearchInputProps) { const input = useRef(null); return ( { if (input.current) { input.current.focus(); } }} > ), endAdornment: ( { if (!value && input.current) { input.current.value = ''; } if (onResetValue) { onResetValue(); } }} > ), ...(rest.InputProps ?? {}), }} /> ); } export default SearchInput;