Search code examples
javascriptleafletsidebar

Leaflet Sidebar V2 set default to open


I'm using Leaflet's Sidebar V2 plugin and it's working great, but I would like to have it open by default. So when the page loads, the sidebar is open but can be collapsed rather than the other way around. Is there a way this can be done?

Thank you in advance!


Solution

  • Just after you add the sidebar to the map, use the method open().

    The argument of the method is the name of the tab.

    var sidebar = L.control.sidebar('sidebar').addTo(map);
    
    sidebar.open('home');