Skip to content

Commit

Permalink
81901: AdminSidebarSectionComponent navigate on spacebar
Browse files Browse the repository at this point in the history
  • Loading branch information
ybnd committed Aug 16, 2021
1 parent 7ae26d3 commit 2a10f6b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
[attr.aria-labelledby]="'sidebarName-' + section.id"
[title]="('menu.section.icon.' + section.id) | translate"
[routerLink]="itemModel.link"
(keyup.space)="navigate($event)"
href="javascript:void(0);"
>
<div class="shortcut-icon">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { rendersSectionForMenu } from '../../../shared/menu/menu-section.decorat
import { LinkMenuItemModel } from '../../../shared/menu/menu-item/models/link.model';
import { MenuSection } from '../../../shared/menu/menu.reducer';
import { isNotEmpty } from '../../../shared/empty.util';
import { Router } from '@angular/router';

/**
* Represents a non-expandable section in the admin sidebar
Expand All @@ -26,7 +27,12 @@ export class AdminSidebarSectionComponent extends MenuSectionComponent implement
menuID: MenuID = MenuID.ADMIN;
itemModel;
hasLink: boolean;
constructor(@Inject('sectionDataProvider') menuSection: MenuSection, protected menuService: MenuService, protected injector: Injector,) {
constructor(
@Inject('sectionDataProvider') menuSection: MenuSection,
protected menuService: MenuService,
protected injector: Injector,
protected router: Router,
) {
super(menuSection, menuService, injector);
this.itemModel = menuSection.model as LinkMenuItemModel;
}
Expand All @@ -35,4 +41,11 @@ export class AdminSidebarSectionComponent extends MenuSectionComponent implement
this.hasLink = isNotEmpty(this.itemModel?.link);
super.ngOnInit();
}

navigate(event: any): void {
event.stopPropagation();
if (this.hasLink) {
this.router.navigate(this.itemModel.link);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ describe('ExpandableAdminSidebarSectionComponent', () => {
{ provide: 'sectionDataProvider', useValue: { icon: iconString } },
{ provide: MenuService, useValue: menuService },
{ provide: CSSVariableService, useClass: CSSVariableServiceStub },
{ provide: Router, useValue: new RouterStub() },
]
}).overrideComponent(ExpandableAdminSidebarSectionComponent, {
set: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { MenuService } from '../../../shared/menu/menu.service';
import { combineLatest as combineLatestObservable, Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { rendersSectionForMenu } from '../../../shared/menu/menu-section.decorator';
import { Router } from '@angular/router';

/**
* Represents a expandable section in the sidebar
Expand Down Expand Up @@ -49,9 +50,14 @@ export class ExpandableAdminSidebarSectionComponent extends AdminSidebarSectionC
*/
expanded: Observable<boolean>;

constructor(@Inject('sectionDataProvider') menuSection, protected menuService: MenuService,
private variableService: CSSVariableService, protected injector: Injector) {
super(menuSection, menuService, injector);
constructor(
@Inject('sectionDataProvider') menuSection,
protected menuService: MenuService,
private variableService: CSSVariableService,
protected injector: Injector,
protected router: Router,
) {
super(menuSection, menuService, injector, router);
}

/**
Expand Down

0 comments on commit 2a10f6b

Please sign in to comment.