diff --git a/src/app/navbar/expandable-navbar-section/expandable-navbar-section.component.html b/src/app/navbar/expandable-navbar-section/expandable-navbar-section.component.html index 5991f9b7538..43c4b47122b 100644 --- a/src/app/navbar/expandable-navbar-section/expandable-navbar-section.component.html +++ b/src/app/navbar/expandable-navbar-section/expandable-navbar-section.component.html @@ -3,10 +3,10 @@ *ngVar="(active | async) as isActive" (keyup.enter)="isActive ? deactivateSection($event) : activateSection($event)" (keyup.space)="isActive ? deactivateSection($event) : activateSection($event)" - (click)="!isActive && activateSection($event)" + (click)="toggleSection($event)" (keydown.space)="$event.preventDefault()" - (mouseenter)="activateSection($event)" - (mouseleave)="deactivateSection($event)"> + (mouseenter)="onMouseEnter($event, isActive)" + (mouseleave)="onMouseLeave($event, isActive)"> ; + + @HostListener('window:resize', ['$event']) + onResize() { + this.isMobile$.pipe( + first() + ).subscribe((isMobile) => { + if (isMobile && !this.wasMobile) { + this.wasMobile = true; + this.menuService.deactivateSection(this.menuID, this.section.id); + this.mouseEntered = false; + } + }); + } + constructor(@Inject('sectionDataProvider') menuSection, protected menuService: MenuService, protected injector: Injector, private windowService: HostWindowService ) { super(menuSection, menuService, injector); + this.isMobile$ = this.windowService.isMobile(); } ngOnInit() { super.ngOnInit(); } + onMouseEnter($event: Event, isActive: boolean) { + if (!isActive && !this.mouseEntered) { + this.activateSection($event); + } + this.mouseEntered = true; + } + + onMouseLeave($event: Event, isActive: boolean) { + if (isActive && this.mouseEntered) { + this.deactivateSection($event); + } + this.mouseEntered = false; + } + /** * Overrides the super function that activates this section (triggered on hover) * Has an extra check to make sure the section can only be activated on non-mobile devices * @param {Event} event The user event that triggered this function */ activateSection(event): void { - this.windowService.isXsOrSm().pipe( + this.isMobile$.pipe( first() ).subscribe((isMobile) => { if (!isMobile) { @@ -54,7 +98,7 @@ export class ExpandableNavbarSectionComponent extends NavbarSectionComponent imp * @param {Event} event The user event that triggered this function */ deactivateSection(event): void { - this.windowService.isXsOrSm().pipe( + this.isMobile$.pipe( first() ).subscribe((isMobile) => { if (!isMobile) {