Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug(tabs): tabset select fires too often #610

Closed
Sethcran opened this issue Jun 13, 2016 · 0 comments
Closed

bug(tabs): tabset select fires too often #610

Sethcran opened this issue Jun 13, 2016 · 0 comments

Comments

@Sethcran
Copy link

Sethcran commented Jun 13, 2016

tab.directive.ts has the following code:

public ngOnDestroy():void {
    this.tabset.removeTab(this);
}

Inside this removeTab call is some code that causes the active property to be set on a new tab (if the tab we're removing was previously active). This setter in turn emits the select event.

When the containing component is destroyed, this causes each tab to be destroyed, which can trigger a select if a new tab is activated. This one in turn being destroyed, triggers another one, etc.

This can cause problems when the (select) event handler has side effects.

For Example: When using the tabs with the router such that each tab content is tied to a url:

<tabset>
    <tab *ngFor="let tab of tabs" [heading]="tab.name" [active]="tab.active" (select)="navigate(tab.path)"></tab>
</tabset>
<router-outlet></router-outlet>

where the navigate call is defined as such:

navigate(route: string) {
    this.router.navigate(['/someroute', route]);
}

In this case, attempting to navigate away from this page from a child component (tab content with a [routerLink] / router.navigate / window.location.href) causes the tabs to be destroyed before the tabset is destroyed. This can cause several extra select events to be fired, which triggers navigation to a child page, overriding the childs navigate call.

Removing the OnDestroy of the tab.directive.ts fixes this problem for me, but I'm not sure if this breaks some other use case.

Will see if I have time to get up a repro plunkr later tonight once I get home.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants