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

fix(material/tabs): Eliminate ExpressionChanged... errors for active tab changes #28380

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 30 additions & 2 deletions src/material/tabs/tab-nav-bar/tab-nav-bar.spec.ts
@@ -1,6 +1,6 @@
import {ENTER, SPACE} from '@angular/cdk/keycodes';
import {waitForAsync, ComponentFixture, fakeAsync, TestBed, tick} from '@angular/core/testing';
import {Component, QueryList, ViewChild, ViewChildren} from '@angular/core';
import {Component, Input, QueryList, ViewChild, ViewChildren} from '@angular/core';
import {MAT_RIPPLE_GLOBAL_OPTIONS, RippleGlobalOptions} from '@angular/material/core';
import {By} from '@angular/platform-browser';
import {
Expand All @@ -11,7 +11,7 @@ import {
import {Direction, Directionality} from '@angular/cdk/bidi';
import {Subject} from 'rxjs';
import {MatTabsModule} from '../module';
import {MatTabLink, MatTabNav} from './tab-nav-bar';
import {MatTabLink, MatTabNav, MatTabNavPanel} from './tab-nav-bar';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
import {MAT_TABS_CONFIG} from '../index';

Expand Down Expand Up @@ -493,6 +493,34 @@ describe('MatTabNavBar with a default config', () => {
expect(indicatorElement.parentElement).toBe(contentElement);
});
});
it('allows tab panel to be in component above nav bar', () => {
@Component({
standalone: true,
selector: 'nav-wrapper',
imports: [MatTabsModule],
template: `
<nav mat-tab-nav-bar [tabPanel]="tabPanel">
<a mat-tab-link [active]="true"> link </a>
</nav>
`,
})
class NavWrapper {
@Input() tabPanel!: MatTabNavPanel;
}

@Component({
standalone: true,
imports: [MatTabsModule, NavWrapper],
template: `
<mat-tab-nav-panel #tabPanel />
<nav-wrapper [tabPanel]="tabPanel" />
`,
})
class TabPanelCmp {}

const comp = TestBed.createComponent(TabPanelCmp);
expect(() => comp.detectChanges()).not.toThrow();
});

describe('MatTabNavBar with enabled animations', () => {
beforeEach(fakeAsync(() => {
Expand Down
7 changes: 4 additions & 3 deletions src/material/tabs/tab-nav-bar/tab-nav-bar.ts
Expand Up @@ -24,6 +24,7 @@ import {
OnDestroy,
Optional,
QueryList,
signal,
ViewChild,
ViewEncapsulation,
} from '@angular/core';
Expand Down Expand Up @@ -211,7 +212,7 @@ export class MatTabNav
this._changeDetectorRef.markForCheck();

if (this.tabPanel) {
this.tabPanel._activeTabId = items[i].id;
this.tabPanel._activeTabId.set(items[i].id);
}

return;
Expand Down Expand Up @@ -416,7 +417,7 @@ export class MatTabLink
exportAs: 'matTabNavPanel',
template: '<ng-content></ng-content>',
host: {
'[attr.aria-labelledby]': '_activeTabId',
'[attr.aria-labelledby]': '_activeTabId()',
'[attr.id]': 'id',
'class': 'mat-mdc-tab-nav-panel',
'role': 'tabpanel',
Expand All @@ -430,5 +431,5 @@ export class MatTabNavPanel {
@Input() id = `mat-tab-nav-panel-${nextUniqueId++}`;

/** Id of the active tab in the nav bar. */
_activeTabId?: string;
_activeTabId = signal<string | undefined>(undefined);
}