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

Ensure toggled Accordion only triggers one event on change of active Card #2934

Merged
merged 1 commit into from
Nov 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions panel/layout/accordion.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,20 @@ def _apply_style(self, i):
def _set_active(self, *events):
if self._updating_active:
return
active = []
self._updating_active = True
try:
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
if self.toggle and not events[0].new:
active = [list(self._panels.values()).index(events[0].obj)]
else:
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)

if not self.toggle or active:
self.active = active
finally:
self._updating_active = False

Expand Down
31 changes: 31 additions & 0 deletions panel/tests/layout/test_accordion.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,45 @@ def test_accordion_active(document, comm, accordion):
def test_accordion_set_card_collapsed(document, comm, accordion):
accordion.get_root(document, comm=comm)

events = []

accordion.param.watch(lambda e: events.append(e), 'active')

c1, c2 = accordion._panels.values()

c1.collapsed = False
assert accordion.active == [0]

assert len(events) == 1

c2.collapsed = False
assert accordion.active == [0, 1]

assert len(events) == 2

c1.collapsed = True
c2.collapsed = True
assert accordion.active == []

assert len(events) == 4


def test_accordion_set_card_collapsed_toggle(document, comm, accordion):
accordion.toggle = True
accordion.get_root(document, comm=comm)

events = []

accordion.param.watch(lambda e: events.append(e), 'active')

c1, c2 = accordion._panels.values()

c1.collapsed = False
assert accordion.active == [0]

assert len(events) == 1

c2.collapsed = False
assert accordion.active == [1]

assert len(events) == 2