Event arguments #13671
Labels
area-blazor
Includes: Blazor, Razor Components
enhancement
This issue represents an ask for new feature or an enhancement to an existing one
✔️ Resolution: Duplicate
Resolved as a duplicate of another issue
Status: Resolved
Milestone
This is about blazor.
Is your feature request related to a problem? Please describe.
Currently, event bubbling works in blazor, but there isn't a way to find out which child element triggered the event.
For example:
Clicking on
div2
will trigger theOnClick
handler, but you need to make a JS call in order to find out which element was actually clicked -div2
ordiv3
.Describe the solution you'd like
A way to find out which element was clicked. Exposing event.target is probably not possible due to wasm and it might not be necessary - what I need is rather an "identifier" for the event.target element rather than the element itself. For example, sending some specific attributes like
id
orclass
might be enough - if the<span class="expand-icon"></span>
is clicked, getting itsclass
can be used to trigger custom logic (e.g. "expand" or "collapse"). If using specific attributes is not possible due to some synchronizations problems with the DOM, candata-
attributes be used instead, e.g.This should mean that the developer is responsible for providing the event.target "information" (`data-id="Id") explicitly and then handling it.
Additional context
This can be handled from JS and JS is probably better suited for more advanced scenarios, but maybe the
UIMouseEventArgs
class can expose some additional props for handling simpler scenarios. This might be also possible with using custom blazor components and exposing specific events, but this fails in cases with templates. For example, if the end user of the blazor component can completely override the "default" component that is used in the template. However, by using specific classes/attributes the overriden component might still work as theOnClick
event handler checks for them.The text was updated successfully, but these errors were encountered: