diff --git a/src/components/biggive-main-menu/biggive-main-menu.scss b/src/components/biggive-main-menu/biggive-main-menu.scss index 6d7a4b8d..06d0b04a 100644 --- a/src/components/biggive-main-menu/biggive-main-menu.scss +++ b/src/components/biggive-main-menu/biggive-main-menu.scss @@ -433,6 +433,11 @@ nav { display: block !important; } +#nav-primary .display-sub-menu, #nav-primary .display-sub-menu li { + background-color: white; +} + + .sub-menu-main { position: absolute; top: $upper-nav-height-desktop; diff --git a/src/components/biggive-main-menu/biggive-main-menu.tsx b/src/components/biggive-main-menu/biggive-main-menu.tsx index acd23ccc..334345cb 100644 --- a/src/components/biggive-main-menu/biggive-main-menu.tsx +++ b/src/components/biggive-main-menu/biggive-main-menu.tsx @@ -94,12 +94,29 @@ export class BiggiveMainMenu { throw new Error('Missing subMenuElements'); } + /** + * Closes all the sub-menus except the one exception. + */ + const closeAllSubMenus = ({ except }: { except: HTMLAnchorElement }) => { + subMenuElements.forEach(subMenuElement => { + const link = subMenuElement.parentElement?.querySelector('a'); + + if (link === except) { + return; + } + + link?.classList.remove('transform-90'); + subMenuElement.classList.remove('display-sub-menu'); + }); + }; + subMenuElements.forEach(subMenuElement => { // the subMenuLink is a sibling element to the actual sub-menu const subMenuLink = subMenuElement.parentElement?.querySelector('a'); subMenuLink!.onclick = () => { const subMenuArrow = subMenuLink!.querySelector('.sub-menu-arrow'); + closeAllSubMenus({ except: subMenuLink! }); subMenuArrow!.classList.toggle('transform-90'); subMenuElement.classList.toggle('display-sub-menu'); };