Skip to content

Commit

Permalink
fix: Search input clear event
Browse files Browse the repository at this point in the history
  • Loading branch information
ccallendar committed Jul 17, 2024
1 parent 115e6e6 commit 0c8679c
Showing 1 changed file with 22 additions and 25 deletions.
47 changes: 22 additions & 25 deletions frontend/src/pages/map/components/SearchInput.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChangeEvent, useEffect, useRef, useState } from 'react'
import { useEffect, useRef, useState } from 'react'
import { useDispatch, useSelector } from 'react-redux'
import { Autocomplete, InputAdornment, TextField } from '@mui/material'
import { LatLngTuple } from 'leaflet'
Expand Down Expand Up @@ -79,8 +79,7 @@ export function SearchInput() {
}, delay)
}

const onTextChange = (ev: ChangeEvent<HTMLInputElement>) => {
const newValue = ev.target.value
const onTextChange = (_ev: any, newValue: string) => {
setValue(newValue)
currentValueRef.current = newValue
delayedSearch(newValue)
Expand Down Expand Up @@ -112,32 +111,31 @@ export function SearchInput() {

return (
<Autocomplete
renderInput={(params) => {
return (
<TextField
{...params}
InputProps={{
...params.InputProps,
startAdornment: (
<InputAdornment position="start">
<SearchIcon title="Search icon" className="map-search-icon" />
</InputAdornment>
),
}}
placeholder="Search"
variant="outlined"
className="map-search-input"
sx={styles}
value={value}
onChange={onTextChange}
/>
)
}}
renderInput={(params) => (
<TextField
{...params}
InputProps={{
...params.InputProps,
startAdornment: (
<InputAdornment position="start">
<SearchIcon title="Search icon" className="map-search-icon" />
</InputAdornment>
),
}}
placeholder="Search"
variant="outlined"
className="map-search-input"
sx={styles}
value={value}
/>
)}
options={options}
loading={loading}
open={open}
onOpen={() => setOpen(true)}
onClose={() => setOpen(false)}
onInputChange={onTextChange}
onChange={onAutocompleteChange}
filterOptions={(options: SearchOption[]) => options}
getOptionKey={(option: string | SearchOption) =>
typeof option === 'string' ? option : option.id
Expand All @@ -151,7 +149,6 @@ export function SearchInput() {
return <SearchResultItem key={key} option={option} {...optionProps} />
}}
componentsProps={componentProps}
onChange={onAutocompleteChange}
/>
)
}

0 comments on commit 0c8679c

Please sign in to comment.