mapbox-gl-geocoder icon indicating copy to clipboard operation
mapbox-gl-geocoder copied to clipboard

should not refocus after selecting result

Open jayenashar opened this issue 4 years ago • 6 comments

please consider adding an option to disable this:

      this._inputEl.focus();
      this._inputEl.scrollLeft = 0;
      this._inputEl.setSelectionRange(0, 0);

semi-related: imho, on focus, it should this._inputEl.select() - but not a big enough issue for me to make a github issue

jayenashar avatar Jun 21 '20 11:06 jayenashar

this is an issue with this example code @andrewharvey gave for https://github.com/mapbox/mapbox-gl-geocoder/issues/364#issuecomment-644495347 as it ends up re-geocoding after selecting a result.

geocoder._inputEl.addEventListener('focus', function () {
  geocoder._geocode(geocoder._inputEl.value);
});

jayenashar avatar Jun 21 '20 11:06 jayenashar

Sorry I don't follow. Could you re-phase this from the public API or user facing perspective?

_inputEl is private, not part of the public API, so while I did post about it before to try and hack something together, I'm more interested in issues affecting the public API or user experience.

andrewharvey avatar Jun 22 '20 14:06 andrewharvey

as a user, after i select a result, i expect:

  • the soft keyboard to be closed (any touch screen but especially on mobile)
  • the results to not be visible

jayenashar avatar Jun 22 '20 15:06 jayenashar

Okay I understand now, so after selecting a result the input element remains focused with the blinker moved to the start which on mobile leaves the keyboard open which is not desired, and this is happening due to this part of the code

https://github.com/mapbox/mapbox-gl-geocoder/blob/668639b94280459ffd9101aa2c3cfa36f142fbed/lib/index.js#L384-L391

I agree, as a user I would expect that selecting a result wouldn't leave the keyboard open and wouldn't leave the cursor blinker in the text input. For me the results are not visible after selecting one, if you're seeing otherwise could you post a minimal reproducible example please?

@samanpwbb what do you think about this? I see you added some of this code recently, what's the reason for moving the cursor to the start and leaving the input element focused after selecting a result, which on mobile (or at least on Android) leaves the keyboard open?

andrewharvey avatar Jun 23 '20 00:06 andrewharvey

For me the results are not visible after selecting one, if you're seeing otherwise could you post a minimal reproducible example please?

The results are only still visible because of the sample @andrewharvey gave for https://github.com/mapbox/mapbox-gl-geocoder/issues/364#issuecomment-644495347 as it ends up re-geocoding after selecting a result.

geocoder._inputEl.addEventListener('focus', function () {
  geocoder._geocode(geocoder._inputEl.value);
});

jayenashar avatar Jun 23 '20 06:06 jayenashar

+1 to this issue. On mobile, it's really bad user experience to have the keyboard still open after a user has selected a location and is expecting to be able to see the map.

tomhalley avatar Aug 13 '22 14:08 tomhalley