MudMenu: Stop contextmenu event propagation when right-click activation is used#10728
Conversation
…rarchical menus This change ensures that the context-menu event does not propagate to parent elements, preventing undesired behavior in hierarchical menu structures where nested menus could inadvertently trigger actions in their ancestors.
Updated the advanced example documentation to include the `@oncontextmenu:stopPropagation` modifier. This ensures that right-click events on the custom `div` do not propagate to parent elements, preventing unintended behavior in nested menu structures.
|
This question might be better suited for a discussion elsewhere rather than as a comment on this pull request, but I was wondering: Would it be possible to allow dismissing the Potential solutions might include:
It could perhaps be tied to if the What are your thoughts? |
That seems fairly niche, what is your use case? And yeah a new issue might be a good place to track it. |
The behavior I want to address is somewhat niche but could be considered intuitive once custom right-click context menus are introduced to a UI. My use case involves displaying items in a tree view and a data grid, each with its own context menu offering various actions. When testing, my instinct was to right-click on one item to show its context menu and then right-click on another item to open its menu as well. However, this caused the browser's default context menu to appear while my custom MudMenu was still displayed. This conflicted with the expectation that only the custom menu should be shown. Upon investigating, I noticed an overlay element being added to the page. Its purpose seemed to be dismissing the MudMenu when clicking outside of it. My interim solution was to write a script that listens for Ideally, the behavior should mimic that of a file explorer: right-clicking any item that has a context menu should immediately show that item's menu, closing any other context menu that is already open. This approach would provide a consistent and expected user experience. By enabling the |
|
I crated an issue for it, for further discussion and how this could be implemented in a good way (if at all) #10738 |
|



Description
This pull request addresses an issue where the contextmenu event was propagating when right-click activation was used in MudMenu. This caused unintended behavior in scenarios with nested elements.
The PR introduces the
@oncontextmenu:stopPropagationmodifier to:MudMenucomponent's default behavior.divis used to trigger theMudMenu.This ensures that the event does not propagate to parent elements, preventing conflicts in hierarchical structures.
How Has This Been Tested?
stopPropagationbehavior works as expected.Type of Changes
Checklist
dev).