Skip to content

Commit f9fa1e4

Browse files
authored
feat(navigable-tab): add change detection trigger (#1410)
* feat(navigable-tab): add change detection trigger When tabs are dynamically added or removed change detection will now be automatically triggered. * refactor(navigable-tab): update change detection trigger mechanism * refactor(navigable-tab): remove unused code
1 parent 216c057 commit f9fa1e4

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

projects/components/src/tabs/navigable/navigable-tab-group.component.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@ import {
88
QueryList
99
} from '@angular/core';
1010
import { ActivatedRoute } from '@angular/router';
11-
import { Color, FeatureState, NavigationParams, NavigationParamsType, NavigationService } from '@hypertrace/common';
11+
import {
12+
Color,
13+
FeatureState,
14+
NavigationParams,
15+
NavigationParamsType,
16+
NavigationService,
17+
queryListAndChanges$
18+
} from '@hypertrace/common';
1219
import { merge, Observable } from 'rxjs';
1320
import { distinctUntilChanged, map, startWith, tap } from 'rxjs/operators';
1421
import { NavigableTabComponent } from './navigable-tab.component';
@@ -20,7 +27,7 @@ import { NavigableTabComponent } from './navigable-tab.component';
2027
template: `
2128
<div class="tab-group">
2229
<nav mat-tab-nav-bar *htLetAsync="this.activeTab$ as activeTab" disableRipple>
23-
<ng-container *ngFor="let tab of this.tabs">
30+
<ng-container *ngFor="let tab of this.tabs$ | async">
2431
<ng-container *ngIf="!tab.hidden">
2532
<div class="tab-button" *htIfFeature="tab.featureFlags | htFeature as featureState">
2633
<ht-link
@@ -53,19 +60,21 @@ import { NavigableTabComponent } from './navigable-tab.component';
5360
})
5461
export class NavigableTabGroupComponent implements AfterContentInit {
5562
@ContentChildren(NavigableTabComponent)
56-
public tabs!: QueryList<NavigableTabComponent>;
63+
private readonly tabs!: QueryList<NavigableTabComponent>;
5764

5865
@Output()
5966
public readonly tabChange: EventEmitter<string | undefined> = new EventEmitter<string | undefined>();
6067

6168
public activeTab$?: Observable<NavigableTabComponent | undefined>;
69+
public tabs$!: Observable<NavigableTabComponent[]>;
6270

6371
public constructor(
6472
public readonly navigationService: NavigationService,
6573
private readonly activatedRoute: ActivatedRoute
6674
) {}
6775

6876
public ngAfterContentInit(): void {
77+
this.tabs$ = queryListAndChanges$(this.tabs).pipe(map(list => list.toArray()));
6978
this.activeTab$ = merge(this.navigationService.navigation$, this.tabs.changes).pipe(
7079
startWith(undefined),
7180
map(() => this.findActiveTab()),

0 commit comments

Comments
 (0)