Is it possible to create a Dialog from a dropdown or context menu?

Hey! I wanted to know if we could trigger dialog creation from a menu item? For example, if there is a list of options and each option has a context menu. And the menu has an item to rename the option, and so the dialog would contain a text area where the user can enter the new name.

If it’s not possible what alternatives would you suggest to this?

1 Like

Here is an example on how to do this:

class State(rx.State):
    open_dialog1: bool = False
    open_dialog2: bool = False


def index():
    return rx.vstack(
        rx.menu.root(
            rx.menu.trigger(rx.text("Menu")),
            rx.menu.content(
                rx.menu.item("Dialog1", on_click=State.setvar("open_dialog1", True)),
                rx.menu.item("Dialog2", on_click=State.setvar("open_dialog2", True)),
            ),
        ),
        # Dialog 1
        rx.dialog.root(
            rx.dialog.content(
                rx.text("Dialog 1"),
                # Add specific content here
                rx.dialog.close(
                    rx.button("Close", on_click=State.setvar("open_dialog1", False))
                ),
            ),
            open=State.open_dialog1,
        ),
        # Dialog 2
        rx.dialog.root(
            rx.dialog.content(
                rx.text("Dialog 2"),
                # Add specific content here
                rx.dialog.close(
                    rx.button("Close", on_click=State.setvar("open_dialog2", False))
                ),
            ),
            open=State.open_dialog2,
        ),
    )
2 Likes

Thank you, this is amazing! :slight_smile:

1 Like