Description
Description
I am trying to use ui.menu and ui.menu_item to create a dropdown menu (think file menu in most applications). If i try and create a dialog window from the function called by on_click, then I get an unexpected response when clicking the menu item.
This enough code to reproduce the issue:
from nicegui import ui
class MenuItemBug:
def compose(self):
with ui.row():
with ui.button("Menu 1"):
with ui.menu():
ui.menu_item("Item 1", on_click=self.on_item_click)
ui.menu_item("Item 2", on_click=self.on_item_click, auto_close=False)
with ui.button("Menu 1"):
with ui.menu():
ui.menu_item("Item 1", on_click=self.on_item_click, auto_close=False)
ui.menu_item("Item 2", on_click=self.on_item_click)
return self
def run(self):
ui.run(port=1004)
def dialog(self):
with ui.dialog(value=True) as _, ui.card():
with ui.column():
ui.label("Bit of a journey to get here!")
def on_item_click(self):
print("click")
self.dialog()
MenuItemBug().compose().run()
If you click a menu item that has auto_close set to False then the dialog opens as expected. However if you click a menu item with auto_close set to True(the default value), "click" is printed to the terminal and the menu closes without opening the dialog. If you reopen the menu then the dialog will then open. I have attached a video showing the behaviour below.
Screen.Recording.2024-12-17.123227.mp4
It seems that the dialog will only be displayed whilst the menu is open.
Is this expected behaviour? An acceptable solution for me would be to leave the menu open while the dialog is displayed, and to close the menu when the dialog is closed. I suspect this is already possible with the existing methods.
I am using python 3.11.0 and nicegui 2.8.1 have attached the requirements.txt from my .venv below
Please let me know if any additional information is required! Thanks