Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search bar: make clearing text easier #322

Merged
merged 1 commit into from
Feb 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/components/SearchBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,19 @@ export default function SearchBar(props) {

const handleFocus = (which, event) => {
dispatch(locationInputFocused(which));

const relevantLocation = which === 'start' ? startLocation : endLocation;
const textModified =
which === 'start' ? startTextModified : endTextModified;
// If the input contains the magic string "Current Location", or if it contains
// unmodified text from the geocoder (often a very long address), select all to
// make it easier to delete.
if (
(which === 'start' &&
startLocation?.source === LocationSourceType.UserGeolocation) ||
(which === 'end' &&
endLocation?.source === LocationSourceType.UserGeolocation)
relevantLocation &&
(relevantLocation.source === LocationSourceType.UserGeolocation ||
(relevantLocation.source === LocationSourceType.Geocoded &&
!textModified))
) {
// Select the "Current Location" text so that any key input will replace it in its
// entirety, since it doesn't make sense to edit this magic string otherwise.
event.target.select();
}
};
Expand Down