e.which is deprecated in VSCode with auxclick in a html web component

112 Views Asked by At

I have a native html web component that simplified looks like the thing below.

What it does is, when clicking on the component element with the middle mouse button, it will be removed. It works just as expected.

class MyComponent extends HTMLElement {
  constructor() {
    super();
  }

  connectedCallback() {
    this.innerHTML = 'Hello World';
    this.onMiddleClick();
  }

  onMiddleClick() {
    this.addEventListener("auxclick", (e) => {
      if (e.which !== 2) return;

      this.remove();
    });
  }
}

customElements.define("my-component", MyComponent);

Problem

VSCode overline which and say that it's deprecated. I tried to change auxclick to mousedown but which is still overlined.

  1. What is wrong?
  2. How can I fix it?
1

There are 1 best solutions below

0
On

It should be e.button. It returns a number and 1 is the middle click.