Skip to content

Commit

Permalink
Ensure Card.collapsed and Accordion.active parameters are synced
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Feb 25, 2021
1 parent 521cd34 commit 8cecd85
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 12 additions & 1 deletion panel/layout/accordion.py
Expand Up @@ -82,6 +82,7 @@ def _get_objects(self, model, old_objects, doc, root, comm=None):
header_css_classes=['accordion-header'],
margin=self.margin
)
card.param.watch(self._set_active, ['collapsed'])
self._panels[id(pane)] = card
card.param.set_param(**params)
if ref in card._models:
Expand All @@ -94,7 +95,6 @@ def _get_objects(self, model, old_objects, doc, root, comm=None):
panel.js_on_change('collapsed', cb)
except RerenderError:
return self._get_objects(model, current_objects[:i], doc, root, comm)

new_models.append(panel)
self._update_cards()
self._update_active()
Expand All @@ -105,6 +105,8 @@ def _cleanup(self, root):
panel._cleanup(root)
super()._cleanup(root)



def _apply_style(self, i):
if i == 0:
margin = (5, 5, 0, 5)
Expand All @@ -114,6 +116,15 @@ def _apply_style(self, i):
margin = (0, 5, 0, 5)
return dict(margin=margin, collapsed = i not in self.active)

def _set_active(self, *events):
active = []
for i, pane in enumerate(self.objects):
if id(pane) not in self._panels:
continue
elif not self._panels[id(pane)].collapsed:
active.append(i)
self.active = active

def _update_active(self, *events):
for i, pane in enumerate(self.objects):
if id(pane) not in self._panels:
Expand Down
2 changes: 2 additions & 0 deletions panel/layout/card.py
Expand Up @@ -49,6 +49,8 @@ class Card(Column):

_bokeh_model = BkCard

_linked_props = ['collapsed']

_rename = dict(Column._rename, title=None, header=None, title_css_classes=None)

def __init__(self, *objects, **params):
Expand Down

0 comments on commit 8cecd85

Please sign in to comment.