Skip to content

Commit d52ef4b

Browse files
committed
fix keyboard tab cycling
1 parent fb910bb commit d52ef4b

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

src/sidebar/search/AddressInput.tsx

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
import { ReactNode, useCallback, useEffect, useRef, useState } from 'react'
22
import { Coordinate, getBBoxFromCoord, QueryPoint, QueryPointType } from '@/stores/QueryStore'
33
import { Bbox, GeocodingHit, ReverseGeocodingHit } from '@/api/graphhopper'
4-
import Autocomplete, {
5-
AutocompleteItem,
6-
GeocodingItem,
7-
POIQueryItem,
8-
} from '@/sidebar/search/AddressInputAutocomplete'
4+
import Autocomplete, { AutocompleteItem, GeocodingItem, POIQueryItem } from '@/sidebar/search/AddressInputAutocomplete'
95

106
import ArrowBack from './arrow_back.svg'
117
import Cross from '@/sidebar/times-solid-thin.svg'
@@ -92,7 +88,6 @@ export default function AddressInput(props: AddressInputProps) {
9288

9389
const onKeypress = useCallback(
9490
(event: React.KeyboardEvent<HTMLInputElement>) => {
95-
const inputElement = event.target as HTMLInputElement
9691
if (event.key === 'Escape') {
9792
setText(origText)
9893
searchInput.current!.blur()
@@ -149,7 +144,7 @@ export default function AddressInput(props: AddressInputProps) {
149144
props.onAddressSelected(item.toText(), item.point)
150145
}
151146
}
152-
searchInput.current!.blur()
147+
if (event.key == 'Enter') searchInput.current!.blur()
153148
break
154149
}
155150
},
@@ -183,8 +178,8 @@ export default function AddressInput(props: AddressInputProps) {
183178
>
184179
<PlainButton
185180
className={styles.btnClose}
186-
onMouseDown={(e) =>
187-
e.preventDefault() // prevents that input->onBlur is called when just "mouse down" event (lose focus only for onClick)
181+
onMouseDown={
182+
e => e.preventDefault() // prevents that input->onBlur is called when just "mouse down" event (lose focus only for onClick)
188183
}
189184
onClick={() => searchInput.current!.blur()}
190185
>
@@ -223,12 +218,13 @@ export default function AddressInput(props: AddressInputProps) {
223218
/>
224219

225220
<PlainButton
221+
tabIndex={-1}
226222
style={text.length == 0 ? { display: 'none' } : {}}
227223
className={styles.btnInputClear}
228-
onMouseDown={(e) =>
229-
e.preventDefault() // prevents that input->onBlur is called when clicking the button (would hide this button and prevent onClick)
224+
onMouseDown={
225+
e => e.preventDefault() // prevents that input->onBlur is called when clicking the button (would hide this button and prevent onClick)
230226
}
231-
onClick={(e) => {
227+
onClick={e => {
232228
setText('')
233229
props.onChange('')
234230
// if we clear the text without focus then explicitly request it to improve usability:
@@ -239,10 +235,11 @@ export default function AddressInput(props: AddressInputProps) {
239235
</PlainButton>
240236

241237
<PlainButton
238+
tabIndex={-1}
242239
style={text.length == 0 && hasFocus ? {} : { display: 'none' }}
243240
className={styles.btnCurrentLocation}
244-
onMouseDown={(e) =>
245-
e.preventDefault() // prevents that input->onBlur is called when clicking the button (would hide this button and prevent onClick)
241+
onMouseDown={
242+
e => e.preventDefault() // prevents that input->onBlur is called when clicking the button (would hide this button and prevent onClick)
246243
}
247244
onClick={() => {
248245
onCurrentLocationSelected(props.onAddressSelected)

0 commit comments

Comments
 (0)