Skip to content

Commit

Permalink
bi ui_select duplicate selected values appearing in the dropdown box (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
CrystalWindSnake authored Dec 8, 2023
1 parent 32ed2a5 commit 5d22048
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
33 changes: 33 additions & 0 deletions __tests/test_bi_ui_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,36 @@ def ds1():
["a", "c1", "0"],
["b", "c1", "200"],
]


def test_update_options(page: ScreenPage, page_path: str):
@ui.page(page_path)
def _():
df = pd.DataFrame(
{
"cls1": [
"x1",
"x1",
"x1",
"x2",
"x2",
"x2",
],
"cls2": ["a", "b", "c", "c", "b", "a"],
}
)
ds = bi.data_source(df)

set_test_id(ds.ui_select("cls1", value="x1", multiple=False), "cls1")
set_test_id(ds.ui_select("cls2", clearable=False), "cls2")

page.open(page_path)

cls1_select = SelectUtils(page, "cls1")
cls2_select = SelectUtils(page, "cls2")

cls2_select.click_and_select("a")
cls1_select.click_and_select("x2")
cls2_select.click_and_select("a")

assert cls2_select.get_selected_values() == []
3 changes: 2 additions & 1 deletion __tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def __init__(self, screen_page: ScreenPage, test_id: str) -> None:
self.target_locator = self.page.get_by_test_id(test_id)

def click(self):
self.target_locator.click()
self.target_locator.click(position={"x": 5, "y": 5})

def get_options_values(self):
return self.page.locator(
Expand All @@ -66,6 +66,7 @@ def click_cancel(self):

def click_and_select(self, value: str):
self.click()
self.page.wait_for_timeout(500)
self.page.get_by_role("option", name=value).click()

def get_input_value(self):
Expand Down
4 changes: 3 additions & 1 deletion ex4nicegui/bi/elements/ui_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ def on_source_update():
if value not in options:
value = ""

cp.set_options(options, value=value)
cp.set_options(options, value=[])
cp.value = value
cp.update()

result = SelectResult(cp, self._dataSource, ref_value)
self._dataSource._register_component(
Expand Down

0 comments on commit 5d22048

Please sign in to comment.