Skip to content

Commit 1a5f070

Browse files
authored
fix: issue with async nav lists not updating correctly (#1032)
1 parent 5819213 commit 1a5f070

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

projects/components/src/navigation/navigation-list.component.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output } from '@angular/core';
1+
import { ChangeDetectionStrategy, Component, EventEmitter, Input, OnChanges, Output } from '@angular/core';
22
import { ActivatedRoute } from '@angular/router';
33
import { IconType } from '@hypertrace/assets-library';
44
import { Color, NavigationService } from '@hypertrace/common';
@@ -25,7 +25,7 @@ import { IconSize } from '../icon/icon-size';
2525
<hr *ngSwitchCase="'${NavItemType.Divider}'" class="nav-divider" />
2626
2727
<ng-container *ngSwitchCase="'${NavItemType.Link}'">
28-
<ht-nav-item [config]="item" [active]="item === activeItem" [collapsed]="this.collapsed"> </ht-nav-item>
28+
<ht-nav-item [config]="item" [active]="item === activeItem" [collapsed]="this.collapsed"></ht-nav-item>
2929
</ng-container>
3030
</ng-container>
3131
</ng-container>
@@ -48,7 +48,7 @@ import { IconSize } from '../icon/icon-size';
4848
</nav>
4949
`
5050
})
51-
export class NavigationListComponent {
51+
export class NavigationListComponent implements OnChanges {
5252
@Input()
5353
public navItems: NavItemConfig[] = [];
5454

@@ -64,12 +64,14 @@ export class NavigationListComponent {
6464
@Output()
6565
public readonly collapsedChange: EventEmitter<boolean> = new EventEmitter();
6666

67-
public readonly activeItem$: Observable<NavItemLinkConfig | undefined>;
67+
public activeItem$?: Observable<NavItemLinkConfig | undefined>;
6868

6969
public constructor(
7070
private readonly navigationService: NavigationService,
7171
private readonly activatedRoute: ActivatedRoute
72-
) {
72+
) {}
73+
74+
public ngOnChanges(): void {
7375
this.activeItem$ = this.navigationService.navigation$.pipe(
7476
startWith(this.navigationService.getCurrentActivatedRoute()),
7577
map(() => this.findActiveItem(this.navItems))

0 commit comments

Comments
 (0)