bikehopper / bikehopper-ui

Friendly bike+transit directions (frontend)
Other
26 stars 1 forks source link

Improve search dropdown and add types #385

Closed graue closed 1 week ago

graue commented 2 weeks ago

Improves the search dropdown:

This also adds and corrects types to a bunch of files, and adds some memoization of callbacks with useCallback. We are now at 89% TypeScript by lines of code within src/.

Keyboard accessibility

Currently, if the input for start point is focused, tabbing will go to the input for end point, which takes away the dropdown suggestions for the start point. This uses tab indexes to make tabbing from the start point go to the dropdown, and only after the last entry in the dropdown will it then tab to the end point. From there, it will tab to the first entry in the dropdown for end point, etc.

It works ok, except that after the end of the dropdown, tab order goes, not to the next element in the SearchBar (that would be the TimeBar's button), but to the map, which is invisible, and then to each of its controls in turn. Adding aria-hidden to the map did not affect this. I'd seemingly have to also set tabIndex={-1} on the map and each of its controls and it looks like ReactMapGL doesn't even have a mechanism for this. Also, hardcoded values for tabIndex spread across two different components (SearchBar and SearchDropdown) is a bit of a hack.

Better options when editing a location selected from recently used, or hydrated from a URL

There are two indirect ways to select locations that were, at some point, geocoded:

  1. Select a geocoded location, and then reload the page or share a link with someone. The location's source is now UrlWithString
  2. Select a recently-used location (from the dropdown when input box is empty)

In both cases, currently, if you then select the input box corresponding to such a location, there are no dropdown suggestions (and in case 2 there's a spinner that spins endlessly). This PR will add suggestions of "Current Location" and any other recently-used locations.