Enhance the left sidebar with dropdown toggles for expandable menu items

This commit is contained in:
aditya.chandel
2025-07-23 23:51:15 -06:00
committed by Aditya Chandel
parent b52e771488
commit f3f59155ed
4 changed files with 69 additions and 66 deletions
@@ -4,11 +4,10 @@ import {animate, state, style, transition, trigger} from '@angular/animations';
import {Subscription} from 'rxjs';
import {filter} from 'rxjs/operators';
import {MenuService} from './service/app.menu.service';
import { AsyncPipe, NgClass } from '@angular/common';
import {AsyncPipe, NgClass} from '@angular/common';
import {Ripple} from 'primeng/ripple';
import {Button} from 'primeng/button';
import {Menu} from 'primeng/menu';
import {MenuItem} from 'primeng/api';
import {UserService} from '../../../settings/user-management/user.service';
@Component({
@@ -52,6 +51,20 @@ export class AppMenuitemComponent implements OnInit, OnDestroy {
menuSourceSubscription: Subscription;
menuResetSubscription: Subscription;
expandedItems = new Set<string>();
toggleExpand(key: string) {
if (this.expandedItems.has(key)) {
this.expandedItems.delete(key);
} else {
this.expandedItems.add(key);
}
}
isExpanded(key: string): boolean {
return this.expandedItems.has(key);
}
constructor(public router: Router, private menuService: MenuService, private userService: UserService) {
this.userService.userState$.subscribe(userData => {
if (userData) {
@@ -85,6 +98,7 @@ export class AppMenuitemComponent implements OnInit, OnDestroy {
ngOnInit() {
this.key = this.parentKey ? this.parentKey + '-' + this.index : String(this.index);
this.expandedItems.add(this.key);
if (this.item.routerLink) {
this.updateActiveStateFromRoute();
}
@@ -116,10 +130,6 @@ export class AppMenuitemComponent implements OnInit, OnDestroy {
this.menuService.onMenuStateChange({key: this.key});
}
get submenuAnimation() {
return this.root ? 'expanded' : (this.active ? 'expanded' : 'collapsed');
}
@HostBinding('class.active-menuitem')
get activeClass() {
return this.active && !this.root;