mardi 7 août 2018

Javascript event.target issue on iOS Safari

I have the following issue, the mobile menu is supposed to remove a .Navi-opened class when the user clicks outside of the .Navi__menuList element.

This works well on Android's Chrome, desktop Chrome, Firefox and Safari, but doesn't remove the class when the user is on iOS' Safari.

There doesn't seem to be any issue with the first part which uses the same e.target.closest method and it still works as expected on iOS. So I assume this isn't cause by either event.target or .closest methods.

If anybody can point me in the right direction, it'll be greatly appreciated.

document.addEventListener("click", function(e) {
  if (e.target.closest('.menu-button')) {
    navi.classList.toggle('Navi-opened');
  }
  else if (e.target.closest(".Navi__menuList")) {
    return;
  } else if (navi.classList.contains("Navi-opened")) {
    navi.classList.remove("Navi-opened");
  }
});

Aucun commentaire:

Enregistrer un commentaire