@@ -42,9 +42,10 @@ export default function AddressInput(props: AddressInputProps) {
4242 const [ hasFocus , setHasFocus ] = useState ( false )
4343 const isSmallScreen = useMediaQuery ( { query : '(max-width: 44rem)' } )
4444
45- // container for geocoding results which gets set by the geocoder class and set to empty if the underlying query point gets changed from outside
46- // also gets filled with an item to select the current location as input if input has focus and geocoding results are
47- // empty
45+ // container for geocoding results which gets set by the geocoder class and set to empty if the underlying query
46+ // point gets changed from outside also gets filled with an item to select the current location as input if input
47+ // has focus and geocoding results are empty
48+ const [ origAutocompleteItems , setOrigAutocompleteItems ] = useState < AutocompleteItem [ ] > ( [ ] )
4849 const [ autocompleteItems , setAutocompleteItems ] = useState < AutocompleteItem [ ] > ( [ ] )
4950 const [ geocoder ] = useState (
5051 new Geocoder ( getApi ( ) , ( query , provider , hits ) => {
@@ -58,10 +59,6 @@ export default function AddressInput(props: AddressInputProps) {
5859 )
5960 } )
6061
61- // TODO autocompleteItems is empty here because query point changed from outside somehow
62- // const res = autocompleteItems.length > 1 ? autocompleteItems.slice(0, autocompleteItems.length - 2) : autocompleteItems
63- // res.concat(items)
64-
6562 setOrigText ( query )
6663 setAutocompleteItems ( items )
6764 } )
@@ -76,6 +73,7 @@ export default function AddressInput(props: AddressInputProps) {
7673
7774 function hideSuggestions ( ) {
7875 geocoder . cancel ( )
76+ setOrigAutocompleteItems ( autocompleteItems )
7977 setAutocompleteItems ( [ ] )
8078 }
8179
@@ -164,8 +162,6 @@ export default function AddressInput(props: AddressInputProps) {
164162 const type = props . point . type
165163
166164 // get the bias point for the geocoder
167- // (the query point above the current one)
168- const autocompleteIndex = props . points . findIndex ( point => ! point . isInitialized )
169165 const lonlat = toLonLat ( getMap ( ) . getView ( ) . getCenter ( ) ! )
170166 const biasCoord = { lng : lonlat [ 0 ] , lat : lonlat [ 1 ] }
171167
@@ -208,6 +204,7 @@ export default function AddressInput(props: AddressInputProps) {
208204 onFocus = { ( ) => {
209205 setHasFocus ( true )
210206 props . clearDragDrop ( )
207+ if ( origAutocompleteItems . length > 0 ) setAutocompleteItems ( origAutocompleteItems )
211208 } }
212209 onBlur = { ( ) => {
213210 if ( ! isSmallScreen ) hideSuggestions ( ) // see #398
0 commit comments