فهرست منبع

use `None` for table selection type "none"

Falko Schindler 3 ماه پیش
والد
کامیت
635a555d44
3فایلهای تغییر یافته به همراه10 افزوده شده و 9 حذف شده
  1. 6 6
      nicegui/elements/table.py
  2. 3 2
      tests/test_table.py
  3. 1 1
      website/documentation/content/table_documentation.py

+ 6 - 6
nicegui/elements/table.py

@@ -35,7 +35,7 @@ class Table(FilterElement, component='table.js'):
                  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 @@ class Table(FilterElement, component='table.js'):
         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*

+ 3 - 2
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):

+ 1 - 1
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))