Skip to content

Commit 985f11b

Browse files
committed
fix(InputSelectize): Fix InputSelectize set method to clear selections
Updated the InputSelectize.set method to remove all selected items before setting new selections. Added regression test and example app to verify that selections are properly cleared when setting an empty list. fixes #2013
1 parent d656fdb commit 985f11b

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

shiny/playwright/controller/_input_controls.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,6 +1197,13 @@ def set(
11971197
if isinstance(selected, str):
11981198
selected = [selected]
11991199
self._loc_events.click()
1200+
1201+
while True:
1202+
remove_button = self._loc_events.locator(".item .remove").first
1203+
if remove_button.count() == 0:
1204+
break
1205+
remove_button.click()
1206+
12001207
for value in selected:
12011208
self._loc_selectize.locator(f"[data-value='{value}']").click(
12021209
timeout=timeout
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from shiny import App, ui
2+
3+
app_ui = ui.page_fluid(
4+
ui.input_selectize("test_selectize", "Select", ["Choice 1", "Choice 2"], multiple=True)
5+
)
6+
7+
def server(input, output, session):
8+
pass
9+
10+
app = App(app_ui, server)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from playwright.sync_api import Page
2+
from shiny.playwright import controller
3+
from shiny.pytest import create_app_fixture
4+
from shiny.run import ShinyAppProc
5+
6+
app = create_app_fixture("app_selectize.py")
7+
8+
def test_inputselectize(page: Page, app: ShinyAppProc):
9+
page.goto(app.url)
10+
11+
controller.InputSelectize(page, "test_selectize").set(["Choice 1"]) # Add Choice 1 to selections
12+
controller.InputSelectize(page, "test_selectize").set(["Choice 1", "Choice 2"]) # Add Choice 2 to selections
13+
controller.InputSelectize(page, "test_selectize").set([]) # Clear selections

0 commit comments

Comments
 (0)