Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[css-om-view] MouseEventInit should allow pageX/Y #4775

Open
timdream opened this issue Feb 13, 2020 · 0 comments
Open

[css-om-view] MouseEventInit should allow pageX/Y #4775

timdream opened this issue Feb 13, 2020 · 0 comments

Comments

@timdream
Copy link

timdream commented Feb 13, 2020

The MouseEvent interface exposes pageX/Y but it doesn't allow the constructor to specify pageX/Y value.

At least on Safari, the pageX/Y value of a constructed MouseEvent (and sub-class instances) will simply be the fix to the value specified in clientX/Y, disregarding the scrolling position of the parent elements when dispatched.

My use case for pageX/Y is to be able to test the event consumption of my own script on the element. I had to result to use something like this:

const rect = targetElement.getBoundingClientRect();
let event = new WheelEvent("wheel", {
        // WheelEventInit
        deltaX: 0,
        deltaY: 4 * (invert ? -1 : 1),
        deltaZ: 0,
        deltaMode: WheelEvent.DOM_DELTA_PIXEL,
        // MouseEventInit
        clientX: rect.x + rect.width / 2,
        clientY: rect.y + rect.height / 2
    });
Object.defineProperty(event, "pageX", { value: rect.x + rect.width / 2 });
Object.defineProperty(event, "pageY", { value: document.scrollingElement.scrollTop + rect.y + rect.height / 2 });
targetElement.dispatchEvent(event);

It will be merrier to be able to specify pageX/Y directly on MouseEventInit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants