Replies: 2 comments 3 replies
-
Hi guys, can someone share at least any link to guide me? |
Beta Was this translation helpful? Give feedback.
0 replies
-
Try something like this import reflex as rx
class State(rx.State):
which_dialog_open: str = ""
def delete(self):
print("Deleted item")
def save_settings(self):
print("Saved settings")
def delete_dialog():
return rx.alert_dialog.root(
rx.alert_dialog.content(
rx.alert_dialog.title("Are you Sure?"),
rx.alert_dialog.description(
rx.text(
"This action cannot be undone. Are you sure you want to delete this item?",
),
margin_bottom="20px",
),
rx.hstack(
rx.alert_dialog.action(
rx.button(
"Delete",
color_scheme="red",
on_click=State.delete,
),
),
rx.spacer(),
rx.alert_dialog.cancel(rx.button("Cancel")),
),
),
open=State.which_dialog_open == "delete",
on_open_change=State.set_which_dialog_open(""),
)
def settings_dialog():
return rx.dialog.root(
rx.dialog.content(
rx.dialog.title("Settings"),
rx.dialog.description(
rx.text("Set your settings in this settings dialog."),
margin_bottom="20px",
),
rx.dialog.close(
rx.button("Close", on_click=State.save_settings),
),
),
open=State.which_dialog_open == "settings",
on_open_change=State.set_which_dialog_open(""),
)
def index() -> rx.Component:
return rx.vstack(
rx.menu.root(
rx.menu.trigger(rx.icon("menu")),
rx.menu.content(
rx.menu.item(
"Delete",
on_click=State.set_which_dialog_open("delete"),
),
rx.menu.item(
"Settings",
on_click=State.set_which_dialog_open("settings"),
),
),
),
rx.cond(
State.which_dialog_open,
rx.heading(f"{State.which_dialog_open} dialog is open"),
),
delete_dialog(),
settings_dialog(),
height="100vh",
align="center",
)
app = rx.App()
app.add_page(index) You cannot use the triggers because the context menu items are ephemeral, so a dialog cannot be "inside" of them. To get around this, I use a state var to control whether or not the dialog is open. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I would like to open appropriate dialog boxes for items present in the Dropdown menu. Assume I have menus like share, delete, download, etc. On selecting these items should open its corresponding dialog box.

Please guide me on how to implement this
Thanks a ton.
Beta Was this translation helpful? Give feedback.
All reactions