Skip to content

MouseEvent: x and y support #3470

@SimonSiefke

Description

@SimonSiefke

Basic info:

  • Node.js version: 18.12.1
  • jsdom version: 20.0.3

Minimal reproduction case

jsdom

import { JSDOM } from "jsdom";

const dom = new JSDOM(`<div></div>`, {});

// @ts-ignore
const { document } = dom.window;

const div = document.querySelector("div");

const handleClick = (event) => {
  const { x, y, clientX, clientY } = event;
  console.log(`x: ${x}`);
  console.log(`y: ${y}`);
  console.log(`clientX: ${clientX}`);
  console.log(`clientY: ${clientY}`);
};
div.addEventListener("click", handleClick);

const event = new MouseEvent("click", {
  clientX: 10,
  clientY: 20,
});
div.dispatchEvent(event);

How does similar code behave in browsers?

x and y properties are printed to the console

chrome

Specification

Link: https://www.w3.org/TR/cssom-view-1/#extensions-to-the-mouseevent-interface

The x attribute must return the value of [clientX](https://www.w3.org/TR/cssom-view-1/#dom-mouseevent-clientx).

The y attribute must return the value of [clientY](https://www.w3.org/TR/cssom-view-1/#dom-mouseevent-clienty).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions