ソースを参照

filter some more event args

Falko Schindler 1 年間 前
コミット
b76e980457

+ 1 - 1
nicegui/elements/menu.py

@@ -55,4 +55,4 @@ class MenuItem(TextElement):
             if auto_close:
             if auto_close:
                 assert isinstance(self.menu, Menu)
                 assert isinstance(self.menu, Menu)
                 self.menu.close()
                 self.menu.close()
-        self.on('click', handle_click)
+        self.on('click', handle_click, [])

+ 1 - 1
nicegui/elements/number.py

@@ -57,7 +57,7 @@ class Number(ValidationElement, DisableableElement):
             self._props['prefix'] = prefix
             self._props['prefix'] = prefix
         if suffix is not None:
         if suffix is not None:
             self._props['suffix'] = suffix
             self._props['suffix'] = suffix
-        self.on('blur', self.sanitize)
+        self.on('blur', self.sanitize, [])
 
 
     @property
     @property
     def min(self) -> float:
     def min(self) -> float:

+ 1 - 1
nicegui/elements/table.py

@@ -61,7 +61,7 @@ class Table(FilterElement):
             self.update()
             self.update()
             arguments = TableSelectionEventArguments(sender=self, client=self.client, selection=self.selected)
             arguments = TableSelectionEventArguments(sender=self, client=self.client, selection=self.selected)
             handle_event(on_select, arguments)
             handle_event(on_select, arguments)
-        self.on('selection', handle_selection)
+        self.on('selection', handle_selection, ['added', 'rows', 'keys'])
 
 
         self.use_component('nicegui-table')
         self.use_component('nicegui-table')
 
 

+ 12 - 12
tests/test_events.py

@@ -54,10 +54,10 @@ def test_click_events(screen: Screen):
 
 
 
 
 def test_generic_events(screen: Screen):
 def test_generic_events(screen: Screen):
-    ui.label('click_sync_no_args').on('click', click_sync_no_args)
-    ui.label('click_sync_with_args').on('click', click_sync_with_args)
-    ui.label('click_async_no_args').on('click', click_async_no_args)
-    ui.label('click_async_with_args').on('click', click_async_with_args)
+    ui.label('click_sync_no_args').on('click', click_sync_no_args, [])
+    ui.label('click_sync_with_args').on('click', click_sync_with_args, [])
+    ui.label('click_async_no_args').on('click', click_async_no_args, [])
+    ui.label('click_async_with_args').on('click', click_async_with_args, [])
 
 
     screen.open('/')
     screen.open('/')
     screen.click('click_sync_no_args')
     screen.click('click_sync_no_args')
@@ -89,10 +89,10 @@ def test_event_with_update_before_await(screen: Screen):
 
 
 def test_event_modifiers(screen: Screen):
 def test_event_modifiers(screen: Screen):
     events = []
     events = []
-    ui.input('A').on('keydown', lambda _: events.append('A'))
-    ui.input('B').on('keydown.x', lambda _: events.append('B'))
-    ui.input('C').on('keydown.once', lambda _: events.append('C'))
-    ui.input('D').on('keydown.shift.x', lambda _: events.append('D'))
+    ui.input('A').on('keydown', lambda _: events.append('A'), [])
+    ui.input('B').on('keydown.x', lambda _: events.append('B'), [])
+    ui.input('C').on('keydown.once', lambda _: events.append('C'), [])
+    ui.input('D').on('keydown.shift.x', lambda _: events.append('D'), [])
 
 
     screen.open('/')
     screen.open('/')
     screen.selenium.find_element(By.XPATH, '//*[@aria-label="A"]').send_keys('x')
     screen.selenium.find_element(By.XPATH, '//*[@aria-label="A"]').send_keys('x')
@@ -104,7 +104,7 @@ def test_event_modifiers(screen: Screen):
 
 
 def test_throttling(screen: Screen):
 def test_throttling(screen: Screen):
     events = []
     events = []
-    ui.button('Test', on_click=lambda: events.append(1)).on('click', lambda: events.append(2), throttle=1)
+    ui.button('Test', on_click=lambda: events.append(1)).on('click', lambda: events.append(2), [], throttle=1)
 
 
     screen.open('/')
     screen.open('/')
     screen.click('Test')
     screen.click('Test')
@@ -124,9 +124,9 @@ def test_throttling(screen: Screen):
 def test_throttling_variants(screen: Screen):
 def test_throttling_variants(screen: Screen):
     events = []
     events = []
     value = 0
     value = 0
-    ui.button('Both').on('click', lambda: events.append(value), throttle=1)
-    ui.button('Leading').on('click', lambda: events.append(value), throttle=1, trailing_events=False)
-    ui.button('Trailing').on('click', lambda: events.append(value), throttle=1, leading_events=False)
+    ui.button('Both').on('click', lambda: events.append(value), [], throttle=1)
+    ui.button('Leading').on('click', lambda: events.append(value), [], throttle=1, trailing_events=False)
+    ui.button('Trailing').on('click', lambda: events.append(value), [], throttle=1, leading_events=False)
 
 
     screen.open('/')
     screen.open('/')
     value = 1
     value = 1

+ 1 - 1
website/demo.py

@@ -50,7 +50,7 @@ def demo(f: Callable) -> Callable:
             ui.markdown(f'````python\n{code}\n````')
             ui.markdown(f'````python\n{code}\n````')
             ui.icon('content_copy', size='xs') \
             ui.icon('content_copy', size='xs') \
                 .classes('absolute right-2 top-10 opacity-10 hover:opacity-80 cursor-pointer') \
                 .classes('absolute right-2 top-10 opacity-10 hover:opacity-80 cursor-pointer') \
-                .on('click', copy_code)
+                .on('click', copy_code, [])
         with browser_window(title=getattr(f, 'tab', None),
         with browser_window(title=getattr(f, 'tab', None),
                             classes='w-full max-w-[44rem] min-[1500px]:max-w-[20rem] min-h-[10rem] browser-window'):
                             classes='w-full max-w-[44rem] min-[1500px]:max-w-[20rem] min-h-[10rem] browser-window'):
             intersection_observer(on_intersection=f)
             intersection_observer(on_intersection=f)

+ 1 - 1
website/documentation_tools.py

@@ -50,7 +50,7 @@ def subheading(text: str, *, make_menu_entry: bool = True, more_link: Optional[s
                 if await ui.run_javascript(f'!!document.querySelector("div.q-drawer__backdrop")'):
                 if await ui.run_javascript(f'!!document.querySelector("div.q-drawer__backdrop")'):
                     menu.hide()
                     menu.hide()
                     ui.open(f'#{name}')
                     ui.open(f'#{name}')
-            ui.link(text, target=f'#{name}').props('data-close-overlay').on('click', click)
+            ui.link(text, target=f'#{name}').props('data-close-overlay').on('click', click, [])
 
 
 
 
 def render_docstring(doc: str, with_params: bool = True) -> ui.html:
 def render_docstring(doc: str, with_params: bool = True) -> ui.html:

+ 2 - 1
website/example_card.py

@@ -8,7 +8,8 @@ def create() -> None:
         with ui.card().style(r'clip-path: polygon(0 0, 100% 0, 100% 90%, 0 100%)') \
         with ui.card().style(r'clip-path: polygon(0 0, 100% 0, 100% 90%, 0 100%)') \
                 .classes('pb-16 no-shadow'), ui.row().classes('no-wrap'):
                 .classes('pb-16 no-shadow'), ui.row().classes('no-wrap'):
             with ui.column().classes('items-center'):
             with ui.column().classes('items-center'):
-                svg.face().classes('w-16 mx-6 stroke-black stroke-2').on('click', lambda _: output.set_text("That's my face!"))
+                svg.face().classes('w-16 mx-6 stroke-black stroke-2') \
+                    .on('click', lambda _: output.set_text("That's my face!"), [])
                 ui.button('Click me!', on_click=lambda: output.set_text('Clicked')).classes('w-full')
                 ui.button('Click me!', on_click=lambda: output.set_text('Clicked')).classes('w-full')
                 ui.input('Text', value='abc', on_change=lambda e: output.set_text(e.value))
                 ui.input('Text', value='abc', on_change=lambda e: output.set_text(e.value))
                 ui.checkbox('Check', on_change=lambda e: output.set_text('Checked' if e.value else 'Unchecked'))
                 ui.checkbox('Check', on_change=lambda e: output.set_text('Checked' if e.value else 'Unchecked'))

+ 1 - 1
website/intersection_observer.py

@@ -14,7 +14,7 @@ class IntersectionObserver(Element):
         super().__init__('intersection_observer')
         super().__init__('intersection_observer')
         self.on_intersection = on_intersection
         self.on_intersection = on_intersection
         self.active = True
         self.active = True
-        self.on('intersection', self.handle_intersection)
+        self.on('intersection', self.handle_intersection, [])
         self.use_component('intersection_observer')
         self.use_component('intersection_observer')
 
 
     def handle_intersection(self, _) -> None:
     def handle_intersection(self, _) -> None:

+ 2 - 1
website/search.py

@@ -55,7 +55,8 @@ class Search:
                 self.results.clear()
                 self.results.clear()
                 for result in results:
                 for result in results:
                     href: str = result['item']['url']
                     href: str = result['item']['url']
-                    with ui.element('q-item').props(f'clickable').on('click', lambda href=href: self.open_url(href)):
+                    with ui.element('q-item').props(f'clickable') \
+                            .on('click', lambda href=href: self.open_url(href), []):
                         with ui.element('q-item-section'):
                         with ui.element('q-item-section'):
                             ui.label(result['item']['title'])
                             ui.label(result['item']['title'])
         background_tasks.create_lazy(handle_input(), name='handle_search_input')
         background_tasks.create_lazy(handle_input(), name='handle_search_input')