mapbox.js
mapbox.js copied to clipboard
Fixing geocoder control keepOpen behavior
When adding a L.mapbox.geocoder
control and setting keepOpen: true
, the results list stays open even after a location is selected. The behavior of keepOpen
should be to keep the search bar open, but to hide the results when the user clicks on the map.
+1, perhaps clicking the magnifying glass icon should dismiss the dropdown as well
Hi @lyzidiamond did you figure out a fix for this issue ? I just started using mapbox for the project and this bug is quite a show-stopper, I have a fairly small map inside a form for the user to enter some information and when the dropdown is open and doesn't close it hides a large part of the map ...
This was not quite how I imagined keepOpen working, and also not what it says on the tin: it means the thing will stay open. I don't get how the search bar would be 'open' - it is a text input and has no open state.
Hi Tom, the thing is by default the input is collapsed you have to click on the magnifying glass icon to display the input.
From my understanding of the documentation at https://www.mapbox.com/mapbox.js/example/v1.0.0/geocoder-keep-open/ the input should be visible by default not the dropdown of the places.
Secondly the first sentence of the page is "Disable toggling to make the geocoder control open by default." which is from my understanding the input control and not the dropdown
i fixed it very dirty with
function clearResults(){
geocoderControl._input.value = "";
geocoderControl._results.innerHTML = ""
}
and attaching it to the needed events
That will not work in all situations though (with more than one map instance for example) and I have not tested fully if the order inside the DOM might change under some circumstances and break this behaviour.