maplibre / maplibre-gl-geocoder

Geocoding for MapLibre
ISC License
57 stars 19 forks source link

Geocoder input does not get focus upon opening #182

Open mvl22 opened 19 hours ago

mvl22 commented 19 hours ago

Currently, when the widget is added to the map, and the user hovers over the search button, the input field is uncollapsed, but the user has to give focus manually by clicking in the input field. This seems unnecessary, given that the user intention will almost always be to want to start typing.

It would therefore be useful to have a focus/autofocus option to add autofocus.

For now, the following workaround will do this:

// Add auto-focus to the widget
document.querySelector ('.maplibregl-ctrl-geocoder').addEventListener ('mouseenter', function () {
    document.querySelector ('.maplibregl-ctrl-geocoder--input').focus ();
});
HarelM commented 18 hours ago

Thanks for taking the time to open this issue! To be honest, I have never interacted with an input that "stills" the focus when you hover it. Moreover, if you accidentally hover over it the map will stop responding to hover, which is not a great UX. This basically "saves" a single click with a mouse your already interact with and is in the right place. Can you showcase a similar behavior in a well known site? I find this behavior a bit odd to be honest...

mvl22 commented 18 hours ago

To be honest, I have never interacted with an input that "stills" the focus when you hover it. Can you showcase a similar behavior in a well known site?

I think the problem is that the collapse mode is quite unusual - most UIs, e.g. Google Maps, have an always-visible control. As a result there is no ambiguity in that scenario.

Here, the user is actually interacting by hovering on the icon, and so it feels odd to have then to select a second time, this time with a click. On the other hand, I accept your point that an accidental hover then leaves the box upon. To me the lack of autofocus feels more problematic.

This basically "saves" a single click with a mouse your already interact with and is in the right place.

At the very least, if the user has actually clicked on the search icon, that is a clear indication of search - at present they still then have to click on the search input.

HarelM commented 8 hours ago

Can you link to a video or a place to better explain the issue, I might not fully understand the problem... Sorry, I've been maintaining this plugin only for a short while...