Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request - use click instead of hover to open/close the control #50

Open
fisharebest opened this issue Apr 29, 2021 · 2 comments
Open

Request - use click instead of hover to open/close the control #50

fisharebest opened this issue Apr 29, 2021 · 2 comments

Comments

@fisharebest
Copy link

At present, the control is opened/closed using mouseover/mouseout events.

This makes it difficult to operate by users with some disabilities and/or assistive technology.

Can you provide an option to open/close this control using mouse-click and/or keyboard?

@jjimenezshaw
Copy link
Owner

This control tries to behave like "Control.Layers" control (https://leafletjs.com/reference-1.7.1.html#control-layers).
As far as I know, there is no such a feature in Leaflet.

However you can capture the events in the DOM, and call the expand() and collapse() methods (probably using also the option collapsed in the control creation)

@albfan
Copy link
Contributor

albfan commented Jun 18, 2023

Basically:

     var layerControlTree = L.control.layers(base, tree, {collapsed: false}).addTo(map);
     
     var collapsed = false
      $('.leaflet-control-layers').on('click', () => {
          if (collapsed)
            layerControlTree.expand();
          else
            layerControlTree.collapse();
          collapsed = !collapsed
      });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants