66import {
77 Autocomplete ,
88 AutocompleteRenderInputParams ,
9- InputAdornment ,
9+ FormHelperText ,
1010 SxProps ,
1111 TextField ,
1212 Theme ,
1313 useTheme
1414} from '@mui/material' ;
15- import SearchIcon from '@mui/icons-material/Search' ;
1615import { HTMLAttributes } from 'react' ;
16+ import { FieldError } from 'react-hook-form' ;
1717
1818interface NERAutocompleteProps {
1919 id : string ;
@@ -25,6 +25,7 @@ interface NERAutocompleteProps {
2525 value ?: { label : string ; id : string } | null ;
2626 listboxProps ?: HTMLAttributes < HTMLUListElement > ;
2727 filterSelectedOptions ?: boolean ;
28+ errorMessage ?: FieldError ;
2829}
2930
3031const NERAutocomplete : React . FC < NERAutocompleteProps > = ( {
@@ -36,23 +37,17 @@ const NERAutocomplete: React.FC<NERAutocompleteProps> = ({
3637 sx,
3738 value,
3839 listboxProps,
39- filterSelectedOptions
40+ filterSelectedOptions,
41+ errorMessage
4042} ) => {
4143 const theme = useTheme ( ) ;
4244
4345 const autocompleteStyle = {
4446 height : '40px' ,
4547 backgroundColor : theme . palette . background . default ,
4648 width : '100%' ,
47- borderRadius : '25px' ,
4849 border : 0 ,
49- '.MuiOutlinedInput-notchedOutline' : {
50- borderColor : 'black' ,
51- borderRadius : '25px'
52- } ,
53- '&.Mui-focused .MuiOutlinedInput-notchedOutline' : {
54- borderColor : 'red'
55- } ,
50+ borderColor : 'black' ,
5651 ...sx
5752 } ;
5853
@@ -61,12 +56,7 @@ const NERAutocomplete: React.FC<NERAutocompleteProps> = ({
6156 < TextField
6257 { ...params }
6358 InputProps = { {
64- ...params . InputProps ,
65- startAdornment : (
66- < InputAdornment position = "start" >
67- < SearchIcon />
68- </ InputAdornment >
69- )
59+ ...params . InputProps
7060 } }
7161 placeholder = { placeholder }
7262 required
@@ -75,19 +65,22 @@ const NERAutocomplete: React.FC<NERAutocompleteProps> = ({
7565 } ;
7666
7767 return (
78- < Autocomplete
79- isOptionEqualToValue = { ( option , value ) => option . id === value . id }
80- disablePortal
81- id = { id }
82- onChange = { onChange }
83- options = { options }
84- sx = { autocompleteStyle }
85- size = { size }
86- renderInput = { autocompleteRenderInput }
87- value = { value }
88- filterSelectedOptions = { filterSelectedOptions }
89- ListboxProps = { listboxProps }
90- />
68+ < >
69+ < Autocomplete
70+ isOptionEqualToValue = { ( option , value ) => option . id === value . id }
71+ disablePortal
72+ id = { id }
73+ onChange = { onChange }
74+ options = { options }
75+ sx = { autocompleteStyle }
76+ size = { size }
77+ renderInput = { autocompleteRenderInput }
78+ value = { value }
79+ filterSelectedOptions = { filterSelectedOptions }
80+ ListboxProps = { listboxProps }
81+ />
82+ < FormHelperText error = { ! ! errorMessage } > { errorMessage ?. message } </ FormHelperText >
83+ </ >
9184 ) ;
9285} ;
9386
0 commit comments