Skip to content

Commit

Permalink
use None for table selection type "none"
Browse files Browse the repository at this point in the history
  • Loading branch information
falkoschindler committed Feb 3, 2025
1 parent 56dc5a1 commit 635a555
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
12 changes: 6 additions & 6 deletions nicegui/elements/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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*
Expand Down
5 changes: 3 additions & 2 deletions tests/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion website/documentation/content/table_documentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))


Expand Down

0 comments on commit 635a555

Please sign in to comment.