Aspnetcore: [Blazor] add support for the onmouseenter and onmouseleave dom events in components

Created on 14 Aug 2019  路  5Comments  路  Source: dotnet/aspnetcore

Until preview 7, I could bind an handler to the onmouseenter and onmouseleave events using a syntax similar to onmouseenter="@MouseEnter". Now this syntax is not working anymore and the syntax @onmouseenter="MouseEnter" leads to this runtime error in Blazor Wasm:

Microsoft.JSInterop.JSException: Failed to execute 'setAttribute' on 'Element': '@onmouseenter' is not a valid attribute name.

Describe the solution you'd like

Add the onmouseenter and onmouseleave to the list of the supported mouse events (I don't know if it's just a matter of adding them to the EventHandlers.cs) class.

Additional context

I'm using those events on a div containing a number of other elements. Using the onmouseover and onmouseout events (which are supported) can't be a solution because they're fired when crossing the boudaries of the external div but also whenever the mouse crosses the border of any of the internal elements causing the events to be fired multiple times.

area-blazor enhancement

Most helpful comment

Thanks for contacting us, @ghidello.
You can add a new class called EventHandlers and add define the needed mappings for these event handlers in there (similar to how it's done in the EventHandlers.cs) and it should just work.

All 5 comments

Thanks for contacting us, @ghidello.
You can add a new class called EventHandlers and add define the needed mappings for these event handlers in there (similar to how it's done in the EventHandlers.cs) and it should just work.

I had the same problem and can confirm it works with the workaround of mkArtakMSFT

Thanks a lot @mkArtakMSFT
I've not figured out how but it's working! Thanks again!

Notifying also @miroslavp who asked about the same events on #5501

thanks @mkArtakMSFT , the workaround worked. May I know when can these two events added officially to the EventHandlers.cs? Appreciate your help.

Was this page helpful?
0 / 5 - 0 ratings