Skip to content

Commit 662141b

Browse files
committed
Fix selectize clear logic and expand related tests
Updated the selector for removing selectize items to target only direct children, ensuring correct clearing behavior. Enhanced the test app to display selected values and expanded the test cases to verify selection and clearing of multiple choices.
1 parent 222e962 commit 662141b

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

shiny/playwright/controller/_input_controls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1199,7 +1199,7 @@ def set(
11991199
self._loc_events.click()
12001200

12011201
while True:
1202-
remove_button = self._loc_events.locator(".item .remove").first
1202+
remove_button = self._loc_events.locator("> .item > .remove").first
12031203
if remove_button.count() == 0:
12041204
break
12051205
remove_button.click()
Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1-
from shiny import App, ui
1+
from shiny import App, ui, render
22

33
app_ui = ui.page_fluid(
44
ui.input_selectize(
5-
"test_selectize", "Select", ["Choice 1", "Choice 2"], multiple=True
6-
)
5+
"test_selectize",
6+
"Select",
7+
["Choice 1", "Choice 2", "Choice 3", "Choice 4"],
8+
multiple=True,
9+
),
10+
ui.output_text("test_selectize_output"),
711
)
812

913

1014
def server(input, output, session):
11-
pass
15+
@render.text
16+
def test_selectize_output():
17+
return f"Selected: {', '.join(input.test_selectize())}"
1218

1319

1420
app = App(app_ui, server)

tests/playwright/shiny/bugs/2013-selectize-set-does-not-clear/test_app_selectize.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@
1010
def test_inputselectize(page: Page, app: ShinyAppProc):
1111
page.goto(app.url)
1212

13-
controller.InputSelectize(page, "test_selectize").set(
14-
["Choice 1"]
15-
) # Add Choice 1 to selections
16-
controller.InputSelectize(page, "test_selectize").set(
17-
["Choice 1", "Choice 2"]
18-
) # Add Choice 2 to selections
19-
controller.InputSelectize(page, "test_selectize").set([]) # Clear selections
13+
input_selectize = controller.InputSelectize(page, "test_selectize")
14+
output_text = controller.OutputText(page, "test_selectize_output")
15+
16+
input_selectize.set(["Choice 1", "Choice 2", "Choice 3"])
17+
output_text.expect_value("Selected: Choice 1, Choice 2, Choice 3")
18+
input_selectize.set(["Choice 2", "Choice 3"])
19+
output_text.expect_value("Selected: Choice 2, Choice 3")
20+
input_selectize.set(["Choice 3"])
21+
output_text.expect_value("Selected: Choice 3")
22+
input_selectize.set([])
23+
output_text.expect_value("Selected: ")

0 commit comments

Comments
 (0)