Context Menu
Anatomy
Right-click menu overlay with support for items, separators, submenus, and destructive actions.
maud_ui::primitives::context_menu
Props
Generated from public Rust fields. Defaults are evaluated from the implementation.
| Prop | Type | Default | Description |
|---|---|---|---|
id | String | No struct Default; supply explicitly | Unique identifier for the menu |
trigger | Markup | No struct Default; supply explicitly | Content that can be right-clicked to trigger the menu |
items | Vec<MenuEntry> | No struct Default; supply explicitly | Menu entries (items, separators, and labels) |
Examples
Right-click the area below
Usage and composition
Import
use maud_ui::primitives::context_menu::{self, Props};
use maud_ui::primitives::menu::{MenuEntry, MenuItem};
Example
use maud::html;
use maud_ui::primitives::{context_menu, menu};
html! {
(context_menu::render(context_menu::Props {
id: "ctx".to_string(),
trigger: html! { div { "Right-click me" } },
items: vec![
menu::MenuEntry::Item(menu::MenuItem {
label: "Cut".into(),
action: "cut".into(),
disabled: false,
destructive: false,
shortcut: Some("⌘X".into()),
}),
menu::MenuEntry::Separator,
],
}))
}
MenuEntry Enum Variants
| Variant | Description |
|---|---|
Item(MenuItem) | A clickable menu item with optional shortcut and destructive flag |
Separator | Visual divider between groups |
Label(String) | Non-interactive group label |
CheckboxItem { label, checked, disabled, action } | Toggle item with checkbox |
RadioGroup(Vec<RadioItem>) | Group of mutually exclusive radio items |
RadioItem { label, value, disabled, action } | Single radio item |
Sub { label, items } | Submenu with nested entries |
Group { label, items } | Grouped items with optional label |
Helper Functions
destructive_item(action, label, disabled, shortcut) → MenuEntry
Builds a MenuEntry::Item pre-set to destructive: true. Use for Delete, Sign out, and other irreversible actions. Applies the mui-menu__item--danger class.
Runtime lifecycle
Following a Nova touch long-press, outside presses during the first 500 ms are ignored, matching the pinned opening grace period. Native right-click opening permits immediate outside dismissal. Closing, history restoration and destruction release the opening timer.
In the Nova profile, closing popups and directly closed submenus stay mounted until their own finite animations finish. Reopening cancels the pending exit. Removing the parent, destroying the runtime or normalizing browser history also cleans up descendant menus and restores any portalled nodes. Caller-authored finite popup animations participate in this lifecycle; infinite animations do not delay removal. The Standard profile retains its existing dismissal behavior. Submenus use their trigger label as the accessible menu name.
Related
- Menu
- Dialog
- Dropdown
Shadcn reference
Accessibility
- Menu has
role="menu"andaria-orientation="vertical" data-side="inline-end"emitted for RTL locale auto-flip of submenus- Items support standard ARIA menu conventions via
menu.rsrenderer