From 2a46e2455fb3b8185dbe0f3a65c6c9f07b61b41b Mon Sep 17 00:00:00 2001 From: Falko Schindler Date: Mon, 15 Apr 2024 11:13:35 +0200 Subject: [PATCH] remove default auto-close prop from `ui.menu` (fixes #2894) --- nicegui/elements/menu.py | 11 +++++------ website/documentation/content/menu_documentation.py | 10 ++++++++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/nicegui/elements/menu.py b/nicegui/elements/menu.py index ce3ffdc80..845928fd0 100644 --- a/nicegui/elements/menu.py +++ b/nicegui/elements/menu.py @@ -17,10 +17,12 @@ def __init__(self, *, value: bool = False) -> None: Creates a menu based on Quasar's `QMenu `_ component. The menu should be placed inside the element where it should be shown. + Advanced tip: + Use the `auto-close` prop to automatically close the menu on any click event directly without a server round-trip. + :param value: whether the menu is already opened (default: `False`) """ super().__init__(tag='q-menu', value=value, on_value_change=None) - self._props['auto-close'] = True def open(self) -> None: """Open the menu.""" @@ -65,11 +67,8 @@ def __init__(self, self._props['clickable'] = True self.menu = self._find_menu() - if self.menu: - if auto_close: - self.on_click(self.menu.close) - else: - self.menu.props(remove='auto-close') + if self.menu and auto_close: + self.on_click(self.menu.close) def _find_menu(self) -> Optional[Union[Menu, ContextMenu]]: element: Element = self diff --git a/website/documentation/content/menu_documentation.py b/website/documentation/content/menu_documentation.py index 04704557c..750371d12 100644 --- a/website/documentation/content/menu_documentation.py +++ b/website/documentation/content/menu_documentation.py @@ -17,4 +17,14 @@ def main_demo() -> None: ui.menu_item('Close', menu.close) +@doc.demo('Client-side auto-close', ''' + Use the `auto-close` prop to automatically close the menu on any click event directly without a server round-trip. +''') +def auto_close(): + with ui.button(icon='menu'): + with ui.menu().props('auto-close'): + toggle = ui.toggle(['fastfood', 'cake', 'icecream'], value='fastfood') + ui.icon('', size='md').bind_name_from(toggle, 'value') + + doc.reference(ui.menu)