question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Simple menu doesn't close when clicked outside of the menu on mobile

See original GitHub issue

What MDC-Web Version are you using?

 "@material/menu": "^0.2.6",

What browser(s) is this bug affecting?

Mobile Chrome and Mobile Safari on iOS

What OS are you using?

iOS 10.3.1

What are the steps to reproduce the bug?

  1. Open this demo page on mobile Safari
  2. click REVEAL MENU to open it
  3. Tap anywhere outside of the menu. See that menu is not closed.

What is the expected behavior?

Menu should be closed when tapped outside. That is the behavior on Google Chrome on desktop.

What is the actual behavior?

When clicked outside of a menu, it is not closed, nothing happens.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:1
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
garrett-thompsoncommented, Dec 21, 2017

Found out this is because iOS doesn’t emit a click event if the element you are tapping on isn’t considered “clickable”.

Workaround is setting all elements as “clickable”

@supports (-webkit-overflow-scrolling: touch) {
  /* CSS specific to iOS devices */
  * {
    cursor: pointer;
  }
}
3reactions
timv88commented, May 24, 2018

Given that you’re listening for a click on the body to close a dropdown, it’s enough to specify cursor: pointer on the body alone

@supports (-webkit-overflow-scrolling: touch) {
  body {
    // fix event bubbling
    cursor: pointer;

    // prevent flashes when tapping the body 
    // you may also need to add this rule on other page wrapping elements depending on your markup
    -webkit-tap-highlight-color: transparent;
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

jquery - Mobile Menu - Click outside menu to close menu
I have that button in my mobile website; the problem is, that I need to add a method that when the user clicks...
Read more >
Close mobile menu when click/tap outside - GeneratePress
Hi,. My mobile menu doesn't close when clicked/tapped outside of it. I would like it to do so. If I have a sub-menu...
Read more >
How To Close The Divi Mobile Menu By Clicking ... - YouTube
In this tutorial I will show you how to close the Divi mobile menu by clicking or touching outside the menu dropdown areaBlog...
Read more >
How To Close The Divi Mobile Menu By ... - Pee-Aye Creative
But not so, it does not do that in Divi. So we created a jQuery snippet to do just that, and in this...
Read more >
Close Div or Menu On Click Outside w/ Javascript - Tech Junkie
In this case, if the menu hasn't been opened yet, there's no reason to listen for a click outside of the menu. Add...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found