Skip to content

How to prevent event propagation in blazor #49308

Closed Answered by david-acker
Xyncgas asked this question in Q&A
Discussion options

You must be logged in to vote

Just to clarify, so since you would not have access to the component itself in this situation, and thus would not be able to use @oncontextmenu:preventDefault="true” to stop propagation, you would need something roughly equivalent to this:

...addEventListener("contextmenu", (ev) => {
  // do stuff
  ev.stopPropagation();
});

but handled in the event handler that's passed to @oncontextmenu, correct?

Unfortunately I don’t believe that this is possible in Blazor since the event would have already occurred (in JS) by the time it reaches the @oncontextmenu handler in .NET. Although I'm not an expert on Blazor, so others might be aware of workarounds or ways to achieve a similar effect.

Note: A…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Xyncgas
Comment options

Answer selected by david-acker
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
area-blazor Includes: Blazor, Razor Components
2 participants