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

setInput bug?

Open anatolysukhanov opened this issue 4 years ago • 4 comments

https://github.com/mapbox/mapbox-gl-geocoder/blob/master/API.md#setinput is used to only populate the input (at least 4.5.1).

So, for intstance, if I call

geocoder.setInput("New York")

I get this:

image

but in the latest version (4.7.0) it has changed and now it shows the results dropdown:

image

Is that a bug or intentional new behaviour?

anatolysukhanov avatar Nov 20 '20 09:11 anatolysukhanov

This behavior was recently introduced via https://github.com/mapbox/mapbox-gl-geocoder/pull/345.

zokioki avatar Nov 23 '20 09:11 zokioki

Just stumbled across this as well. It's hugely problematic if you are trying to prefill the location picker with the current value of the field. You now have only two choices to show:

  1. A blank field
  2. A dropdown open in the middle of your page

I'm certainly eager to see https://github.com/mapbox/mapbox-gl-geocoder/pull/425 merged in order to allow better control over this feature

antony avatar Jul 23 '21 09:07 antony

I encountered the same problem. It's indeed a bit confusing that setInput() leads to new results being shown.

This did the trick for me. It's not ideal, but there doesn't seem to be a better solution.

geocoder._inputEl.value = value;

ghost avatar Oct 04 '21 10:10 ghost

This also works, but am looking forward to #425 as well 😄

const inputElements = document.getElementsByClassName(
  'mapboxgl-ctrl-geocoder--input',
);

if (inputElements.length > 0) {
  inputElements[0].value = "New York";
}

christopherstyles avatar Nov 19 '21 09:11 christopherstyles