Skip to content

Commit 07708bf

Browse files
committed
fixes for mobile view when clicking on back or clearText buttons or not on an autosuggest item
1 parent 8aa4dee commit 07708bf

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/sidebar/search/AddressInput.module.css

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

88
.btnCurrentLocation {
9+
opacity: 1;
10+
transition: opacity 2s ease-in-out;
911
padding: 0 7px 0 5px;
1012
color: grey;
1113
width: 32px;

src/sidebar/search/AddressInput.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ export default function AddressInput(props: AddressInputProps) {
174174
const lonlat = toLonLat(getMap().getView().getCenter()!)
175175
const biasCoord = { lng: lonlat[0], lat: lonlat[1] }
176176

177+
// do not focus on mobile as we would hide the map with the "input"-view
178+
const focusFirstInput = props.index == 0 && !isSmallScreen
179+
177180
return (
178181
<div className={containerClass}>
179182
<div
@@ -201,7 +204,7 @@ export default function AddressInput(props: AddressInputProps) {
201204
style={props.moveStartIndex == props.index ? { borderWidth: '2px', margin: '-1px' } : {}}
202205
className={styles.input}
203206
type="text"
204-
autoFocus={props.index == 0}
207+
autoFocus={focusFirstInput}
205208
ref={searchInput}
206209
autoComplete="off"
207210
onChange={e => {
@@ -219,7 +222,7 @@ export default function AddressInput(props: AddressInputProps) {
219222
}}
220223
onBlur={() => {
221224
setHasFocus(false)
222-
if (!isSmallScreen) hideSuggestions() // see #398
225+
hideSuggestions()
223226
}}
224227
value={text}
225228
placeholder={tr(
@@ -230,11 +233,11 @@ export default function AddressInput(props: AddressInputProps) {
230233
<PlainButton
231234
style={text.length == 0 ? { display: 'none' } : {}}
232235
className={styles.btnInputClear}
236+
// no onClick because otherwise focus would be lost before button receives click
233237
onMouseDown={(e) => {
234238
e.preventDefault() // do not lose focus and close mobile-input view when clicked
235239
setText('')
236240
props.onChange('')
237-
searchInput.current!.focus()
238241
}}
239242
>
240243
<Cross />
@@ -243,6 +246,7 @@ export default function AddressInput(props: AddressInputProps) {
243246
<PlainButton
244247
style={text.length == 0 && hasFocus ? {} : { display: 'none' }}
245248
className={styles.btnCurrentLocation}
249+
// no onClick because otherwise focus would be lost before button receives click
246250
onMouseDown={(e) => {
247251
// here it is desired to close mobile-input view when clicked
248252
onCurrentLocationSelected(props.onAddressSelected)

0 commit comments

Comments
 (0)