From 635a555d44b33aa32760e369938b2f7915f37c39 Mon Sep 17 00:00:00 2001 From: Falko Schindler Date: Mon, 3 Feb 2025 16:47:48 +0100 Subject: [PATCH] use `None` for table selection type "none" --- nicegui/elements/table.py | 12 ++++++------ tests/test_table.py | 5 +++-- website/documentation/content/table_documentation.py | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/nicegui/elements/table.py b/nicegui/elements/table.py index 503dba1d5..7f6751c79 100644 --- a/nicegui/elements/table.py +++ b/nicegui/elements/table.py @@ -35,7 +35,7 @@ def __init__(self, column_defaults: Optional[Dict] = None, row_key: str = 'id', title: Optional[str] = None, - selection: Optional[Literal['single', 'multiple']] = None, + selection: Literal[None, 'single', 'multiple'] = None, pagination: Optional[Union[int, dict]] = None, on_select: Optional[Handler[TableSelectionEventArguments]] = None, on_pagination_change: Optional[Handler[ValueChangeEventArguments]] = None, @@ -323,19 +323,19 @@ def selected(self, value: List[Dict]) -> None: self.update() @property - def selection(self) -> Literal['none', 'single', 'multiple']: + def selection(self) -> Literal[None, 'single', 'multiple']: """Selection type. *Added in version 2.11.0* """ - return self._props['selection'] + return None if self._props['selection'] == 'none' else self._props['selection'] @selection.setter - def selection(self, value: Literal['none', 'single', 'multiple']) -> None: - self._props['selection'] = value + def selection(self, value: Literal[None, 'single', 'multiple']) -> None: + self._props['selection'] = value or 'none' self.update() - def set_selection(self, value: Literal['none', 'single', 'multiple']) -> None: + def set_selection(self, value: Literal[None, 'single', 'multiple']) -> None: """Set the selection type. *Added in version 2.11.0* diff --git a/tests/test_table.py b/tests/test_table.py index 4f3f624d9..11b08f334 100644 --- a/tests/test_table.py +++ b/tests/test_table.py @@ -111,7 +111,8 @@ def test_slots(screen: Screen): def test_selection(screen: Screen): table = ui.table(columns=columns(), rows=rows(), selection='single') - ui.radio(['none', 'single', 'multiple'], on_change=lambda e: table.set_selection(e.value)) + ui.radio({None: 'none', 'single': 'single', 'multiple': 'multiple'}, + on_change=lambda e: table.set_selection(e.value)) screen.open('/') screen.find('Alice').find_element(By.XPATH, 'preceding-sibling::td').click() @@ -133,7 +134,7 @@ def test_selection(screen: Screen): screen.click('none') screen.wait(0.5) screen.should_not_contain('1 record selected.') - assert table.selection == 'none' + assert table.selection is None def test_dynamic_column_attributes(screen: Screen): diff --git a/website/documentation/content/table_documentation.py b/website/documentation/content/table_documentation.py index aa14657bf..3cf9e7c42 100644 --- a/website/documentation/content/table_documentation.py +++ b/website/documentation/content/table_documentation.py @@ -65,7 +65,7 @@ def selection(): row_key='name', on_select=lambda e: ui.notify(f'selected: {e.selection}'), ) - ui.radio(['none', 'single', 'multiple'], value='none', + ui.radio({None: 'none', 'single': 'single', 'multiple': 'multiple'}, on_change=lambda e: table.set_selection(e.value))