Skip to content

Commit ed27231

Browse files
116404: Fixed expandable navbar section loosing focus on expand through keyboard
(cherry picked from commit 2547b12)
1 parent bb977dc commit ed27231

4 files changed

Lines changed: 15 additions & 17 deletions

File tree

src/app/admin/admin-sidebar/expandable-admin-sidebar-section/expandable-admin-sidebar-section.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export class ExpandableAdminSidebarSectionComponent extends AdminSidebarSectionC
8484
this.sidebarActiveBg$ = this.variableService.getVariable('--ds-admin-sidebar-active-bg');
8585
this.isSidebarCollapsed$ = this.menuService.isMenuCollapsed(this.menuID);
8686
this.isSidebarPreviewCollapsed$ = this.menuService.isMenuPreviewCollapsed(this.menuID);
87-
this.isExpanded$ = combineLatestObservable([this.active, this.isSidebarCollapsed$, this.isSidebarPreviewCollapsed$]).pipe(
87+
this.isExpanded$ = combineLatestObservable([this.active$, this.isSidebarCollapsed$, this.isSidebarPreviewCollapsed$]).pipe(
8888
map(([active, sidebarCollapsed, sidebarPreviewCollapsed]) => (active && (!sidebarCollapsed || !sidebarPreviewCollapsed))),
8989
);
9090
}

src/app/navbar/expandable-navbar-section/expandable-navbar-section.component.html

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
<div class="ds-menu-item-wrapper text-md-center"
22
[id]="'expandable-navbar-section-' + section.id"
3-
(mouseenter)="onMouseEnter($event, isActive)"
4-
(mouseleave)="onMouseLeave($event, isActive)"
5-
data-test="navbar-section-wrapper"
6-
*ngVar="(active | async) as isActive">
3+
(mouseenter)="onMouseEnter($event)"
4+
(mouseleave)="onMouseLeave($event)"
5+
data-test="navbar-section-wrapper">
76
<a href="javascript:void(0);" routerLinkActive="active"
87
role="menuitem"
98
(keyup.enter)="toggleSection($event)"
@@ -12,18 +11,17 @@
1211
(keydown.space)="$event.preventDefault()"
1312
aria-haspopup="menu"
1413
data-test="navbar-section-toggler"
15-
[attr.aria-expanded]="isActive"
14+
[attr.aria-expanded]="(active$ | async).valueOf()"
1615
[attr.aria-controls]="expandableNavbarSectionId(section.id)"
1716
class="d-flex flex-row flex-nowrap align-items-center gapx-1 ds-menu-toggler-wrapper"
1817
[class.disabled]="section.model?.disabled">
1918
<span class="flex-fill">
2019
<ng-container
2120
*ngComponentOutlet="(sectionMap$ | async).get(section.id).component; injector: (sectionMap$ | async).get(section.id).injector;"></ng-container>
22-
<!-- <span class="sr-only">{{'nav.expandable-navbar-section-suffix' | translate}}</span>-->
2321
</span>
2422
<i class="fas fa-caret-down fa-xs toggle-menu-icon" aria-hidden="true"></i>
2523
</a>
26-
<div @slide *ngIf="isActive" (click)="deactivateSection($event)"
24+
<div @slide *ngIf="(active$ | async).valueOf() === true" (click)="deactivateSection($event)"
2725
[id]="expandableNavbarSectionId(section.id)"
2826
role="menu"
2927
class="dropdown-menu show nav-dropdown-menu m-0 shadow-none border-top-0 px-3 px-md-0 pt-0 pt-md-1">

src/app/navbar/expandable-navbar-section/expandable-navbar-section.component.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,12 @@ export class ExpandableNavbarSectionComponent extends NavbarSectionComponent imp
8484
/**
8585
* When the mouse enters the section toggler activate the menu section
8686
* @param $event
87-
* @param isActive
8887
*/
89-
onMouseEnter($event: Event, isActive: boolean) {
88+
onMouseEnter($event: Event): void {
9089
this.isMobile$.pipe(
9190
first(),
9291
).subscribe((isMobile) => {
93-
if (!isMobile && !isActive && !this.mouseEntered) {
92+
if (!isMobile && !this.active$.value && !this.mouseEntered) {
9493
this.activateSection($event);
9594
}
9695
this.mouseEntered = true;
@@ -100,13 +99,12 @@ export class ExpandableNavbarSectionComponent extends NavbarSectionComponent imp
10099
/**
101100
* When the mouse leaves the section toggler deactivate the menu section
102101
* @param $event
103-
* @param isActive
104102
*/
105-
onMouseLeave($event: Event, isActive: boolean) {
103+
onMouseLeave($event: Event): void {
106104
this.isMobile$.pipe(
107105
first(),
108106
).subscribe((isMobile) => {
109-
if (!isMobile && isActive && this.mouseEntered) {
107+
if (!isMobile && this.active$.value && this.mouseEntered) {
110108
this.deactivateSection($event);
111109
}
112110
this.mouseEntered = false;

src/app/shared/menu/menu-section/menu-section.component.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ import { MenuSection } from '../menu-section.model';
3737
export class MenuSectionComponent implements OnInit, OnDestroy {
3838

3939
/**
40-
* Observable that emits whether or not this section is currently active
40+
* {@link BehaviorSubject} containing the current state to whether this section is currently active
4141
*/
42-
active: Observable<boolean>;
42+
active$: BehaviorSubject<boolean> = new BehaviorSubject(false);
4343

4444
/**
4545
* The ID of the menu this section resides in
@@ -72,7 +72,9 @@ export class MenuSectionComponent implements OnInit, OnDestroy {
7272
* Set initial values for instance variables
7373
*/
7474
ngOnInit(): void {
75-
this.active = this.menuService.isSectionActive(this.menuID, this.section.id).pipe(distinctUntilChanged());
75+
this.menuService.isSectionActive(this.menuID, this.section.id).pipe(distinctUntilChanged()).subscribe((isActive: boolean) => {
76+
this.active$.next(isActive);
77+
});
7678
this.initializeInjectorData();
7779
}
7880

0 commit comments

Comments
 (0)