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

Fix NestedSelect update options #7649

Merged
merged 4 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
15 changes: 14 additions & 1 deletion panel/tests/ui/widgets/test_select.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import pytest

from playwright.sync_api import expect
philippjfr marked this conversation as resolved.
Show resolved Hide resolved

from panel.tests.util import serve_component, wait_until
from panel.widgets import MultiSelect, Select
from panel.widgets import MultiSelect, NestedSelect, Select

pytestmark = pytest.mark.ui

Expand Down Expand Up @@ -31,3 +33,14 @@ def test_multi_select_double_click(page):
page.locator('option').nth(1).dblclick()

wait_until(lambda: bool(clicks) and clicks[0].option == 'B', page)


def test_nested_select_update_options(page):
n = NestedSelect(options={"a": {"b": ["c", "d"]}})

serve_component(page, n)

expect(page.locator('option').first).to_have_text("a")

n.options = {"c": {"d": ["e", "f"]}}
expect(page.locator('option').first).to_have_text("c")
8 changes: 4 additions & 4 deletions panel/tests/widgets/test_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -800,8 +800,8 @@ def test_nested_select_layout_dict(document, comm):
options=options,
layout={"type": GridBox, "ncols": 2},
)
assert isinstance(select._composite, GridBox)
assert select._composite.ncols == 2
assert isinstance(select._composite[0], GridBox)
assert select._composite[0].ncols == 2


def test_nested_select_layout_dynamic_update(document, comm):
Expand All @@ -819,8 +819,8 @@ def test_nested_select_layout_dynamic_update(document, comm):
options=options,
layout={"type": GridBox, "ncols": 2},
)
assert isinstance(select._composite, GridBox)
assert select._composite.ncols == 2
assert isinstance(select._composite[0], GridBox)
assert select._composite[0].ncols == 2

select.layout = Row
assert isinstance(select._composite, Row)
Expand Down
2 changes: 1 addition & 1 deletion panel/widgets/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ def _update_widgets(self):
f"The layout must be a subclass of ListLike or dict, got {self.layout!r}."
)

self._composite = layout_type(*self._widgets, **layout_kwargs)
self._composite[:] = [layout_type(*self._widgets, **layout_kwargs)]
if self.options is not None:
self.value = self._gather_values_from_widgets()

Expand Down
Loading