Merge pull request #5323 from abpframework/refactor/5160

Hid the menu dropdown when clicking a navigation
pull/5421/head
Levent Arman Özak 5 years ago committed by GitHub
commit 6b742a73fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -60,7 +60,7 @@
<ng-template #defaultChild let-child> <ng-template #defaultChild let-child>
<div class="dropdown-submenu" *abpPermission="child.requiredPolicy"> <div class="dropdown-submenu" *abpPermission="child.requiredPolicy">
<a class="dropdown-item" [routerLink]="[child.path]"> <a class="dropdown-item" [routerLink]="[child.path]" (click)="closeDropdown()">
<i *ngIf="child.iconClass" [ngClass]="child.iconClass"></i> <i *ngIf="child.iconClass" [ngClass]="child.iconClass"></i>
{{ child.name | abpLocalization }}</a {{ child.name | abpLocalization }}</a
> >

@ -1,5 +1,13 @@
import { ABP, RoutesService, TreeNode } from '@abp/ng.core'; import { ABP, RoutesService, TreeNode } from '@abp/ng.core';
import { Component, Input, TrackByFunction } from '@angular/core'; import {
Component,
ElementRef,
Input,
QueryList,
Renderer2,
TrackByFunction,
ViewChildren,
} from '@angular/core';
@Component({ @Component({
selector: 'abp-routes', selector: 'abp-routes',
@ -8,11 +16,20 @@ import { Component, Input, TrackByFunction } from '@angular/core';
export class RoutesComponent { export class RoutesComponent {
@Input() smallScreen: boolean; @Input() smallScreen: boolean;
@ViewChildren('childrenContainer') childrenContainers: QueryList<ElementRef<HTMLDivElement>>;
trackByFn: TrackByFunction<TreeNode<ABP.Route>> = (_, item) => item.name; trackByFn: TrackByFunction<TreeNode<ABP.Route>> = (_, item) => item.name;
constructor(public readonly routes: RoutesService) {} constructor(public readonly routes: RoutesService, protected renderer: Renderer2) {}
isDropdown(node: TreeNode<ABP.Route>) { isDropdown(node: TreeNode<ABP.Route>) {
return !node?.isLeaf || this.routes.hasChildren(node.name); return !node?.isLeaf || this.routes.hasChildren(node.name);
} }
closeDropdown() {
this.childrenContainers.forEach(({ nativeElement }) => {
this.renderer.addClass(nativeElement, 'd-none');
setTimeout(() => this.renderer.removeClass(nativeElement, 'd-none'), 0);
});
}
} }

Loading…
Cancel
Save