Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leaking click handlers on buttons? #2207

Closed
marcin-koziol opened this issue Dec 19, 2023 · 1 comment
Closed

Leaking click handlers on buttons? #2207

marcin-koziol opened this issue Dec 19, 2023 · 1 comment

Comments

@marcin-koziol
Copy link

Description

In this example, the red button should not trigger timer.open(), but it does

from nicegui import ui

with ui.menu() as timer:
    ui.time(value='08:00')
ui.button('', on_click=timer.open).props('icon=calendar_month')

with ui.menu() as timer:
    ui.time(value='16:00')
ui.button('', on_click=timer.open).props('icon=calendar_month')
ui.button('', on_click=lambda: ui.notify("CLICK"), color='negative').props('icon=delete')

ui.run(title='lol 2137', dark=None, show=False)

This one works as expected:

from nicegui import ui

with ui.card():
    with ui.menu() as timer:
        ui.time(value='08:00')
    ui.button('', on_click=timer.open).props('icon=calendar_month')

    with ui.menu() as timer:
        ui.time(value='16:00')
    ui.button('', on_click=timer.open).props('icon=calendar_month')
ui.button('', on_click=lambda: ui.notify("CLICK"), color='negative').props('icon=delete')

ui.run(title='lol 2137', dark=None, show=False)
@falkoschindler
Copy link
Contributor

The intended way would be do nest menus in buttons:

with ui.button().props('icon=calendar_month'):
    with ui.menu() as timer:
        ui.time(value='08:00')

with ui.button().props('icon=calendar_month'):
    with ui.menu() as timer:
        ui.time(value='16:00')

ui.button(on_click=lambda: ui.notify('CLICK'), color='negative').props('icon=delete')

This is because Quasar's QMenu component opens when clicking on its parent container element by default. This is why the menus in your first example also open when clicking on the background. This behavior can be disabled setting the "no-parent-event" prop. In earlier NiceGUI versions this prop was set by default, but in 1.3.0 we decided to switch to Quasar's default. See #713 for more details.

@falkoschindler falkoschindler closed this as not planned Won't fix, can't repro, duplicate, stale Dec 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants