fix for responding to expand event on compacted menu item
- 主要語言
- TypeScript
- 星號
- 8.1k
- 分支
- 1.5k
- PR 合併指標
- 30 天內沒有已合併 PR
描述
in the sidebar.component.ts there is a work-around to send an expand event from the menu to the sidebarService.
i would like to propose a better solution
here is the first solution that currently exists in the code
// TODO: this is more of a workaround, should be a better way to make components communicate to each other
onClick(event): void {
const menu = this.element.nativeElement.querySelector('nb-menu');
if (menu && menu.contains(event.target)) {
const link = this.getMenuLink(event.target);
if (link && link.nextElementSibling && link.nextElementSibling.classList.contains('menu-items')) {
this.sidebarService.expand(this.tag);
}
}
}
my solution is to do the following in ngOnInit
this.menuService.onSubmenuToggle()
.pipe(takeUntil(this.destroy$))
.subscribe((data: { tag: string; item: NbMenuItem }) => {
if (!data.tag || this.tag === data.tag) {
if (data.item.expanded) {
this.sidebarService.expand(data.tag);
}
}
});
this.menuService.onSubmenuToggle()
.pipe(takeUntil(this.destroy$))
.subscribe((data: { tag: string; item: NbMenuItem }) => {
if (!data.tag || this.tag === data.tag)
if (data.item.expanded) {
this.sidebarService.expand(data.tag);
}
});
貢獻指南
評估
這個 Issue 還沒有評估資料。