Skip to content

Commit

Permalink
fix keyboard tab cycling
Browse files Browse the repository at this point in the history
  • Loading branch information
karussell committed Dec 6, 2024
1 parent fb910bb commit d52ef4b
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions src/sidebar/search/AddressInput.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { ReactNode, useCallback, useEffect, useRef, useState } from 'react'
import { Coordinate, getBBoxFromCoord, QueryPoint, QueryPointType } from '@/stores/QueryStore'
import { Bbox, GeocodingHit, ReverseGeocodingHit } from '@/api/graphhopper'
import Autocomplete, {
AutocompleteItem,
GeocodingItem,
POIQueryItem,
} from '@/sidebar/search/AddressInputAutocomplete'
import Autocomplete, { AutocompleteItem, GeocodingItem, POIQueryItem } from '@/sidebar/search/AddressInputAutocomplete'

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

const onKeypress = useCallback(
(event: React.KeyboardEvent<HTMLInputElement>) => {
const inputElement = event.target as HTMLInputElement
if (event.key === 'Escape') {
setText(origText)
searchInput.current!.blur()
Expand Down Expand Up @@ -149,7 +144,7 @@ export default function AddressInput(props: AddressInputProps) {
props.onAddressSelected(item.toText(), item.point)
}
}
searchInput.current!.blur()
if (event.key == 'Enter') searchInput.current!.blur()
break
}
},
Expand Down Expand Up @@ -183,8 +178,8 @@ export default function AddressInput(props: AddressInputProps) {
>
<PlainButton
className={styles.btnClose}
onMouseDown={(e) =>
e.preventDefault() // prevents that input->onBlur is called when just "mouse down" event (lose focus only for onClick)
onMouseDown={
e => e.preventDefault() // prevents that input->onBlur is called when just "mouse down" event (lose focus only for onClick)
}
onClick={() => searchInput.current!.blur()}
>
Expand Down Expand Up @@ -223,12 +218,13 @@ export default function AddressInput(props: AddressInputProps) {
/>

<PlainButton
tabIndex={-1}
style={text.length == 0 ? { display: 'none' } : {}}
className={styles.btnInputClear}
onMouseDown={(e) =>
e.preventDefault() // prevents that input->onBlur is called when clicking the button (would hide this button and prevent onClick)
onMouseDown={
e => e.preventDefault() // prevents that input->onBlur is called when clicking the button (would hide this button and prevent onClick)
}
onClick={(e) => {
onClick={e => {
setText('')
props.onChange('')
// if we clear the text without focus then explicitly request it to improve usability:
Expand All @@ -239,10 +235,11 @@ export default function AddressInput(props: AddressInputProps) {
</PlainButton>

<PlainButton
tabIndex={-1}
style={text.length == 0 && hasFocus ? {} : { display: 'none' }}
className={styles.btnCurrentLocation}
onMouseDown={(e) =>
e.preventDefault() // prevents that input->onBlur is called when clicking the button (would hide this button and prevent onClick)
onMouseDown={
e => e.preventDefault() // prevents that input->onBlur is called when clicking the button (would hide this button and prevent onClick)
}
onClick={() => {
onCurrentLocationSelected(props.onAddressSelected)
Expand Down

0 comments on commit d52ef4b

Please sign in to comment.