mapbox.js icon indicating copy to clipboard operation
mapbox.js copied to clipboard

Fixing geocoder control keepOpen behavior

Open lyzidiamond opened this issue 9 years ago • 5 comments

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.

lyzidiamond avatar Jul 22 '15 22:07 lyzidiamond

+1, perhaps clicking the magnifying glass icon should dismiss the dropdown as well

bdon avatar Oct 08 '15 08:10 bdon

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 ...

simon-jouet avatar Jan 20 '16 21:01 simon-jouet

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.

tmcw avatar Jan 20 '16 21:01 tmcw

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

simon-jouet avatar Jan 20 '16 22:01 simon-jouet

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.

machinaeXphilip avatar Apr 28 '20 08:04 machinaeXphilip