Skip to content

Commit

Permalink
fixes for mobile view when clicking on back or clearText buttons or n…
Browse files Browse the repository at this point in the history
…ot on an autosuggest item
  • Loading branch information
karussell committed Dec 5, 2024
1 parent 8aa4dee commit 07708bf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/sidebar/search/AddressInput.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
}

.btnCurrentLocation {
opacity: 1;
transition: opacity 2s ease-in-out;
padding: 0 7px 0 5px;
color: grey;
width: 32px;
Expand Down
10 changes: 7 additions & 3 deletions src/sidebar/search/AddressInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ export default function AddressInput(props: AddressInputProps) {
const lonlat = toLonLat(getMap().getView().getCenter()!)
const biasCoord = { lng: lonlat[0], lat: lonlat[1] }

// do not focus on mobile as we would hide the map with the "input"-view
const focusFirstInput = props.index == 0 && !isSmallScreen

return (
<div className={containerClass}>
<div
Expand Down Expand Up @@ -201,7 +204,7 @@ export default function AddressInput(props: AddressInputProps) {
style={props.moveStartIndex == props.index ? { borderWidth: '2px', margin: '-1px' } : {}}
className={styles.input}
type="text"
autoFocus={props.index == 0}
autoFocus={focusFirstInput}
ref={searchInput}
autoComplete="off"
onChange={e => {
Expand All @@ -219,7 +222,7 @@ export default function AddressInput(props: AddressInputProps) {
}}
onBlur={() => {
setHasFocus(false)
if (!isSmallScreen) hideSuggestions() // see #398
hideSuggestions()
}}
value={text}
placeholder={tr(
Expand All @@ -230,11 +233,11 @@ export default function AddressInput(props: AddressInputProps) {
<PlainButton
style={text.length == 0 ? { display: 'none' } : {}}
className={styles.btnInputClear}
// no onClick because otherwise focus would be lost before button receives click
onMouseDown={(e) => {
e.preventDefault() // do not lose focus and close mobile-input view when clicked
setText('')
props.onChange('')
searchInput.current!.focus()
}}
>
<Cross />
Expand All @@ -243,6 +246,7 @@ export default function AddressInput(props: AddressInputProps) {
<PlainButton
style={text.length == 0 && hasFocus ? {} : { display: 'none' }}
className={styles.btnCurrentLocation}
// no onClick because otherwise focus would be lost before button receives click
onMouseDown={(e) => {
// here it is desired to close mobile-input view when clicked
onCurrentLocationSelected(props.onAddressSelected)
Expand Down

0 comments on commit 07708bf

Please sign in to comment.