mapbox-gl-geocoder
mapbox-gl-geocoder copied to clipboard
setInput bug?
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:
but in the latest version (4.7.0) it has changed and now it shows the results dropdown:
Is that a bug or intentional new behaviour?
This behavior was recently introduced via https://github.com/mapbox/mapbox-gl-geocoder/pull/345.
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:
- A blank field
- 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
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;
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";
}