From ff2c2772882beea032e34e276be7d8705a4f0d2a Mon Sep 17 00:00:00 2001 From: Raghav Sharma <118168183+sharmrj@users.noreply.github.com> Date: Tue, 23 Apr 2024 20:20:35 +0530 Subject: [PATCH] MWPW-146129 [Original: #2123] App Launcher overlaps the menu in Unav in the devices (#2184) * Closes the global nav expanded wrapper in non desktop viewports when the user interacts with the universal nav (Notifications, app switcher, and profile/sign in button) * We no longer use element.click * made toggleMenuMobile a method of the Gnav class * Extracted the toggle expanded check into its own function * a little cleanup --- .../global-navigation/global-navigation.js | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/libs/blocks/global-navigation/global-navigation.js b/libs/blocks/global-navigation/global-navigation.js index d0c8e80e41..2726eeed22 100644 --- a/libs/blocks/global-navigation/global-navigation.js +++ b/libs/blocks/global-navigation/global-navigation.js @@ -280,6 +280,9 @@ class Gnav { if (this.useUniversalNav) { delete this.blocks.profile; this.blocks.universalNav = toFragment`
`; + this.blocks.universalNav.addEventListener('click', () => { + if (this.isToggleExpanded()) this.toggleMenuMobile(); + }, true); } }; @@ -615,6 +618,18 @@ class Gnav { }); }; + isToggleExpanded = () => this.elements.mobileToggle?.getAttribute('aria-expanded') === 'true'; + + toggleMenuMobile = () => { + const toggle = this.elements.mobileToggle; + const isExpanded = this.isToggleExpanded(); + toggle?.setAttribute('aria-expanded', !isExpanded); + this.elements.navWrapper?.classList?.toggle('feds-nav-wrapper--expanded', !isExpanded); + closeAllDropdowns(); + setCurtainState(!isExpanded); + toggle?.setAttribute('daa-ll', `hamburgermenu|${isExpanded ? 'open' : 'close'}`); + }; + decorateToggle = () => { if (!this.mainNavItemCount) return ''; @@ -638,12 +653,7 @@ class Gnav { }; const onToggleClick = async () => { - const isExpanded = toggle.getAttribute('aria-expanded') === 'true'; - toggle.setAttribute('aria-expanded', !isExpanded); - this.elements.navWrapper.classList.toggle('feds-nav-wrapper--expanded', !isExpanded); - closeAllDropdowns(); - setCurtainState(!isExpanded); - toggle.setAttribute('daa-ll', `hamburgermenu|${isExpanded ? 'open' : 'close'}`); + this.toggleMenuMobile(); if (this.blocks?.search?.instance) { this.blocks.search.instance.clearSearchForm(); @@ -651,7 +661,7 @@ class Gnav { await this.loadSearch(); } - if (isExpanded) setHamburgerPadding(); + if (this.isToggleExpanded()) setHamburgerPadding(); }; toggle.addEventListener('click', () => logErrorFor(onToggleClick, 'Toggle click failed', 'errorType=error,module=gnav'));