Skip to content

Commit 57bee16

Browse files
committed
further cleanup
1 parent 7a43778 commit 57bee16

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

src/sidebar/search/AddressInput.module.css

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
}
77

88
.btnCurrentLocation {
9-
opacity: 1;
10-
transition: opacity 2s ease-in-out;
119
padding: 0 7px 0 5px;
1210
color: grey;
1311
width: 32px;

src/sidebar/search/AddressInput.tsx

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,6 @@ export default function AddressInput(props: AddressInputProps) {
7979
// if item is selected we need to clear the autocompletion list
8080
useEffect(() => setAutocompleteItems([]), [props.point])
8181

82-
function hideSuggestions() {
83-
geocoder.cancel()
84-
setOrigAutocompleteItems(autocompleteItems)
85-
setAutocompleteItems([])
86-
}
87-
8882
// highlighted result of geocoding results. Keep track which index is highlighted and change things on ArrowUp and Down
8983
// on Enter select highlighted result or the 0th if nothing is highlighted
9084
const [highlightedResult, setHighlightedResult] = useState<number>(-1)
@@ -188,6 +182,9 @@ export default function AddressInput(props: AddressInputProps) {
188182
>
189183
<PlainButton
190184
className={styles.btnClose}
185+
onMouseDown={(e) =>
186+
e.preventDefault() // prevents that input->onBlur is called when just "mouse down" event (lose focus only for a proper click)
187+
}
191188
onClick={() => searchInput.current!.blur()}
192189
>
193190
<ArrowBack />
@@ -214,7 +211,9 @@ export default function AddressInput(props: AddressInputProps) {
214211
}}
215212
onBlur={() => {
216213
setHasFocus(false)
217-
hideSuggestions()
214+
geocoder.cancel()
215+
setOrigAutocompleteItems(autocompleteItems)
216+
setAutocompleteItems([])
218217
}}
219218
value={text}
220219
placeholder={tr(
@@ -226,11 +225,13 @@ export default function AddressInput(props: AddressInputProps) {
226225
style={text.length == 0 ? { display: 'none' } : {}}
227226
className={styles.btnInputClear}
228227
onMouseDown={(e) =>
229-
e.preventDefault() // prevents that input->onBlur is called when clicking the button
228+
e.preventDefault() // prevents that input->onBlur is called when clicking the button (would hide this button and prevent onClick)
230229
}
231230
onClick={(e) => {
232231
setText('')
233232
props.onChange('')
233+
// if we clear the text without focus then explicitely request it:
234+
searchInput.current!.focus()
234235
}}
235236
>
236237
<Cross />
@@ -240,11 +241,11 @@ export default function AddressInput(props: AddressInputProps) {
240241
style={text.length == 0 && hasFocus ? {} : { display: 'none' }}
241242
className={styles.btnCurrentLocation}
242243
onMouseDown={(e) =>
243-
e.preventDefault() // prevents that input->onBlur is called when clicking the button (loosing focus would hide this button)
244+
e.preventDefault() // prevents that input->onBlur is called when clicking the button (would hide this button and prevent onClick)
244245
}
245246
onClick={() => {
246247
onCurrentLocationSelected(props.onAddressSelected)
247-
// but when clicked => we want to loose the focuse e.g. to close mobile-input view
248+
// but when clicked => we want to lose the focus e.g. to close mobile-input view
248249
searchInput.current!.blur()
249250
}}
250251
>
@@ -261,12 +262,9 @@ export default function AddressInput(props: AddressInputProps) {
261262
items={autocompleteItems}
262263
highlightedItem={autocompleteItems[highlightedResult]}
263264
onSelect={item => {
264-
setHasFocus(false)
265265
if (item instanceof GeocodingItem) {
266-
hideSuggestions()
267266
props.onAddressSelected(item.toText(), item.point)
268267
} else if (item instanceof POIQueryItem) {
269-
hideSuggestions()
270268
handlePoiSearch(poiSearch, item.result, props.map)
271269
setText(item.result.text(item.result.poi))
272270
}

0 commit comments

Comments
 (0)