Menu
Displays a menu to the user — such as a set of actions or functions — triggered by a button.
Installation
Command to install the Menu component.
Component Guide
Use the following to build the Menu component.
from components.ui.menu import menuSource Code & Dependencies
For manual installation, copy each of the source codes below in their respective locations.
components/core/core.py
components/ui/menu.py
Examples
Basic
A clean dropdown menu with organizational group labels and visual dividers.
Props used: None.
Shortcuts
Dropdown items with right-aligned keyboard command hints built into the row layout.
Props used: menu.shortcut as a child wrapper element.
Icons
Row entries decorated with left-side action icons for clean visual scanning.
Props used: hi <hugeicon> as an inline child prefix element.
Destructive
Incorporate warning styles into individual items for irreversible actions.
Props used: variant="destructive" on menu.item.
API Reference
menu.root
Instantiates a positioning context container built around a native HTML <details> disclosure component. Includes automated JavaScript listeners for document keydowns (Escape) and window click-away dismissals.
menu.root(
menu.trigger("Open Menu"),
menu.content(...)
)
menu.trigger
Nested Interactivity Constraint: Do not pass fully interactive components (like standard
button(...)blocks) as children insidemenu.trigger. Nesting interactive elements intercepts DOM click events and prevents the menu from opening. To style your trigger like a button, pass raw strings/icons and apply button classes directly to the trigger component.
The target control wrapper that toggles the open visibility state of the menu list container. Generates a native HTML <summary> element.
menu.trigger("Click me")
menu.content
Layout Boundaries: This component utilizes pure CSS absolute positioning instead of DOM portaling. The popup menu remains nested deep inside its localized DOM tree node. Ensure that no parent container layouts above this component enforce overflow: hidden or overflow: auto constraints, as this will physically clip or crop the floating dropdown menu box.
The relative positioning wrapper box holding the collection of links or action rows.
menu.content(
menu.item("Item 1"),
side="bottom",
align="start"
)
menu.item
An action selection row component. Injects a DOM traversal action snippet that walks up to collapse the parent menu immediately upon clicking.
Loop Context Warning: If rendered inside an
rx.foreach, pass an explicitidderived from your loop data (e.g.id=f"menu-item-{item.id}") to prevent static template collisions.
menu.item("Profile", variant="default", close_on_click=True)
menu.close
An item selection layout button dedicated entirely to dismissing and closing the menu panel on click. Perfect for layout rows acting explicitly as "Cancel" buttons.
menu.close("Cancel Action", class_name="text-center justify-center")
menu.separator
A thematic breakout line used to separate distinct clusters of menu content actions horizontally.
menu.separator()
menu.group_label
Renders an accessible, small, grayed-out header label row ideal for categorizing sets of items inside multi-tiered menus.
menu.group_label("Workspace Actions")
menu.shortcut
A right-aligned utility container used to cleanly position semantic keyboard shortcuts or button prompt hints inside a menu.item.
menu.item(
"Save Project",
menu.shortcut("Ctrl + S")
)