fix(mobile-menu): ignore click if mobile menu is hidden

This commit is contained in:
MDLeom 2020-04-12 10:18:12 +01:00
parent b36b898a17
commit 7ce52e381a
No known key found for this signature in database
GPG Key ID: 5D9DB57A25D34EE3
1 changed files with 4 additions and 2 deletions

View File

@ -14,9 +14,11 @@ document.addEventListener('click', (evt) => {
const mobileToggle = document.getElementById('mobile-menu-toggle') const mobileToggle = document.getElementById('mobile-menu-toggle')
const isClickedOutside = !mobileNav.contains(evt.target) const isClickedOutside = !mobileNav.contains(evt.target)
// Exit if not in mobile view or menu button is clicked // Exit if not in mobile view or menu button is clicked or menu is currently hidden
// Menu button click triggers `menu-button` and `mobile-menu-toggle` // Menu button click triggers `menu-button` and `mobile-menu-toggle`
if (mainNavDisplay !== 'none' || evt.target.id === 'menu-button' || evt.target.id === 'mobile-menu-toggle') return if (mainNavDisplay !== 'none' ||
evt.target.id === 'menu-button' || evt.target.id === 'mobile-menu-toggle' ||
mobileToggle.checked === false) return
if (isClickedOutside) { if (isClickedOutside) {
mobileToggle.checked = false mobileToggle.checked = false