Ilan Roitlender
Ilan Roitlender

Reputation: 21

safari click event not triggert on iphone

click event not working on mobile when opening from safari on iphone

In react class component, when opening the menu I trigger click events listener on the window. it's working fine anywhere except on Iphone Safari

toggleMenu = async() => {
  if (this.state.isOpen) {
    this.handleCloseMenu();
  } else {
    await this.setState({
      isOpen: true
    });
    window.addEventListener('click', this.handleClick);
    disableBodyScroll(this.targetElement);
  }
};

handleClick = ({
  path
}: E) => {
  const btnClicked = path.find(node => node === this.hamburgerBtn.current);

  if (!btnClicked) {
    const menuClicked = path.find(node => node === this.targetElement.current);

    if (!menuClicked) {
      this.handleCloseMenu();
    }
  }
};

Upvotes: 2

Views: 919

Answers (1)

jean3xw
jean3xw

Reputation: 121

click is a mouse event. Still there no mouse on a Iphone there're no mouse event. You've to use the touchpad with such:

 document.body.addEventListener('touchstart', function(e){
 alert(e.changedTouches[0].pageX) // alert pageX coordinate of touch point
}, false);

Upvotes: 4

Related Questions