Skip to content

UIMouseEventArgs should include OffsetX and OffsetY #8241

Closed
@petergolde

Description

@petergolde

I'm using Razor Components (server-side Blazor) to handle mouse events on a canvas element, although the issue could arise with any HTML element. I would like to know where on the canvas element the mouse event occurred (obviously a key piece of data!)

Currently, UIMouseEventArgs includes only ScreenX/Y and ClientX/Y. Neither of these directly give the location of the mouse event within the element. Typically, JavaScript code will call getBoundingClientRect() on the given element, and subtract those values from ClientX/Y to get the mouse location with the element.

Doing that using server-side Blazor presents two problems. First, it requires another round-trip to the client to make that Javascript call. This is a performance problem. Second, because that Javascript call is asynchronous, the bounding client rect might have changed since the event happened. For example, the web page might have scrolled or there might be an animation occurring. In that case, the adjusted mouse coordinates still won't be correct.

In order to remedy this, I think that UIMouseEventArgs should include two new fields: OffsetX and OffsetY, which indicate the position within that element that the mouse event occurred. Most modern browsers already include those properties on mouse events; for those that do not, the client size Blazor code should provide the trivial emulation.

Metadata

Metadata

Assignees

Labels

DoneThis issue has been fixedarea-blazorIncludes: Blazor, Razor ComponentsenhancementThis issue represents an ask for new feature or an enhancement to an existing one

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions