Skip to content

Commit

Permalink
new clear text button instead of selecting text which doesn't work in…
Browse files Browse the repository at this point in the history
… Safari
  • Loading branch information
karussell committed Sep 2, 2023
1 parent 026f4a6 commit dd159b8
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
27 changes: 26 additions & 1 deletion src/sidebar/search/AddressInput.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@
position: relative;
}

.btnInputClear {
display: none;
}

.inputContainer:hover .btnInputClear {
/* duplicate code, see (clear) */
display: block;
background-color: white;
margin-left: -35px;
padding: 0 5px;
color: gray;
scale: 0.7;
}

.btnClose {
display: none;
}
Expand Down Expand Up @@ -35,7 +49,7 @@
}

.fullscreen .inputContainer {
grid-template-columns: auto 1fr;
grid-template-columns: auto 1fr auto;
}

.fullscreen .smallList {
Expand All @@ -47,6 +61,17 @@
margin: 0;
padding: 5px 15px 5px 5px;
}

.fullscreen .inputContainer:hover .btnInputClear,
.fullscreen .btnInputClear {
/* duplicate code, see (clear) */
display: block;
background-color: white;
margin-left: -35px;
padding: 0 5px;
color: gray;
scale: 0.7;
}
}

.topBorder {
Expand Down
19 changes: 17 additions & 2 deletions src/sidebar/search/AddressInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Autocomplete, {
} from '@/sidebar/search/AddressInputAutocomplete'

import ArrowBack from './arrow_back.svg'
import Cross from '@/sidebar/times-solid-thin.svg'
import styles from './AddressInput.module.css'
import Api, { getApi } from '@/api/Api'
import { tr } from '@/translation/Translation'
Expand Down Expand Up @@ -161,10 +162,9 @@ export default function AddressInput(props: AddressInputProps) {
props.onChange(e.target.value)
}}
onKeyDown={onKeypress}
onFocus={event => {
onFocus={() => {
setHasFocus(true)
props.clearSelectedInput()
event.target.select()
}}
onBlur={() => {
// Suppress onBlur if there was a click on a suggested item.
Expand All @@ -179,6 +179,21 @@ export default function AddressInput(props: AddressInputProps) {
type == QueryPointType.From ? 'from_hint' : type == QueryPointType.To ? 'to_hint' : 'via_hint'
)}
/>
{text.length > 0 && (
<PlainButton
className={styles.btnInputClear}
onMouseDown={() => setPointerDownOnSuggestion(true)}
onMouseLeave={() => setPointerDownOnSuggestion(false)}
onMouseUp={() => setPointerDownOnSuggestion(false)}
onClick={() => {
setText('')
props.onChange('')
searchInput.current!.focus()
}}
>
<Cross />
</PlainButton>
)}

{autocompleteItems.length > 0 && (
<ResponsiveAutocomplete inputRef={searchInput.current!} isSmallScreen={isSmallScreen}>
Expand Down
1 change: 1 addition & 0 deletions src/sidebar/times-solid-thin.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit dd159b8

Please sign in to comment.