Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

e.initEvent is deprecated #532

Open
wilbertopachecob opened this issue Oct 6, 2021 · 0 comments
Open

e.initEvent is deprecated #532

wilbertopachecob opened this issue Oct 6, 2021 · 0 comments

Comments

@wilbertopachecob
Copy link

e.initEvent(type, true, true);

Hi
First of all great work, I love this library!
Is it possible to refactor the trigger function since the initEvent is now deprecated according to Mozilla?
https://developer.mozilla.org/en-US/docs/Web/API/Event/initEvent
Instead we could check if the current environment supports the new Event API, something like this:

export const trigger = (el, type) => {
  let e;
  if (window.Event) {
    e = new window.Event(type, { bubbles: true, cancelable: true });
  } else {
    e = document.createEvent("HTMLEvents");
    e.initEvent(type, true, true);
  }
  el.dispatchEvent(e);
};
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants