@@ -32,15 +32,12 @@ import {ThemePalette, MatRipple} from '@angular/material/core';
3232import { merge , Subscription } from 'rxjs' ;
3333import { MAT_TABS_CONFIG , MatTabsConfig } from './tab-config' ;
3434import { startWith } from 'rxjs/operators' ;
35- import { CdkMonitorFocus , FocusOrigin } from '@angular/cdk/a11y' ;
35+ import { _IdGenerator , CdkMonitorFocus , FocusOrigin } from '@angular/cdk/a11y' ;
3636import { MatTabBody } from './tab-body' ;
3737import { CdkPortalOutlet } from '@angular/cdk/portal' ;
3838import { MatTabLabelWrapper } from './tab-label-wrapper' ;
3939import { Platform } from '@angular/cdk/platform' ;
4040
41- /** Used to generate unique ID's for each tab component */
42- let nextId = 0 ;
43-
4441/** @docs -private */
4542export interface MatTabGroupBaseHeader {
4643 _alignInkBarToSelectedTab ( ) : void ;
@@ -268,7 +265,7 @@ export class MatTabGroup implements AfterContentInit, AfterContentChecked, OnDes
268265 @Output ( ) readonly selectedTabChange : EventEmitter < MatTabChangeEvent > =
269266 new EventEmitter < MatTabChangeEvent > ( true ) ;
270267
271- private _groupId : number ;
268+ private _groupId : string ;
272269
273270 /** Whether the tab group is rendered on the server. */
274271 protected _isServer : boolean = ! inject ( Platform ) . isBrowser ;
@@ -278,7 +275,7 @@ export class MatTabGroup implements AfterContentInit, AfterContentChecked, OnDes
278275 constructor ( ) {
279276 const defaultConfig = inject < MatTabsConfig > ( MAT_TABS_CONFIG , { optional : true } ) ;
280277
281- this . _groupId = nextId ++ ;
278+ this . _groupId = inject ( _IdGenerator ) . getId ( 'mat-tab-group-' ) ;
282279 this . animationDuration =
283280 defaultConfig && defaultConfig . animationDuration ? defaultConfig . animationDuration : '500ms' ;
284281 this . disablePagination =
@@ -492,12 +489,12 @@ export class MatTabGroup implements AfterContentInit, AfterContentChecked, OnDes
492489
493490 /** Returns a unique id for each tab label element */
494491 _getTabLabelId ( i : number ) : string {
495- return `mat-tab-label- ${ this . _groupId } -${ i } ` ;
492+ return `${ this . _groupId } -label -${ i } ` ;
496493 }
497494
498495 /** Returns a unique id for each tab content element */
499496 _getTabContentId ( i : number ) : string {
500- return `mat-tab-content- ${ this . _groupId } -${ i } ` ;
497+ return `${ this . _groupId } -content -${ i } ` ;
501498 }
502499
503500 /**
0 commit comments