holoviz / panel

Panel: The powerful data exploration & web app framework for Python
https://panel.holoviz.org
BSD 3-Clause "New" or "Revised" License
4.66k stars 506 forks source link

Programatic control over the sidebar in Templates #2557

Open sdc50 opened 3 years ago

sdc50 commented 3 years ago

When using panel Templates I would like the ability to trigger the sidebar to open or close programmatically, similar to the .open_modal() and .close_modal() methods. Could .open_sidebar() and .close_sidebar() methods be added?

MarcSkovMadsen commented 3 years ago

Hi @sdc50

Could you describe the use case?

should it be a method or a parameter like sidebar_open?

sdc50 commented 3 years ago

Could you describe the use case? should it be a method or a parameter like sidebar_open?

My use case is that I'd like the home page of my app to load without the sidebar open. I've made the header dynamic, so I don't want the side bar open while it's changing size.

panel_template_sidbare

My current approach is to use JavaScript to programatically trigger a click event on the sidebar hamburger toggle:

var nav_toggle = document.getElementsByClassName('mdc-top-app-bar__navigation-icon')[0];
  if(document.getElementById('sidebar').classList.contains('mdc-drawer--open')){
    nav_toggle.click();
  }

I think a cleaner approach would be to specify that the sidebar should initialize as closed in Python.

In my opinion, this should just be a method rather than a parameter. That way the state doesn't require syncing every time the sidebar is toggled from the interface.