@@ -32,15 +32,12 @@ import {ThemePalette, MatRipple} from '@angular/material/core';
32
32
import { merge , Subscription } from 'rxjs' ;
33
33
import { MAT_TABS_CONFIG , MatTabsConfig } from './tab-config' ;
34
34
import { startWith } from 'rxjs/operators' ;
35
- import { CdkMonitorFocus , FocusOrigin } from '@angular/cdk/a11y' ;
35
+ import { _IdGenerator , CdkMonitorFocus , FocusOrigin } from '@angular/cdk/a11y' ;
36
36
import { MatTabBody } from './tab-body' ;
37
37
import { CdkPortalOutlet } from '@angular/cdk/portal' ;
38
38
import { MatTabLabelWrapper } from './tab-label-wrapper' ;
39
39
import { Platform } from '@angular/cdk/platform' ;
40
40
41
- /** Used to generate unique ID's for each tab component */
42
- let nextId = 0 ;
43
-
44
41
/** @docs -private */
45
42
export interface MatTabGroupBaseHeader {
46
43
_alignInkBarToSelectedTab ( ) : void ;
@@ -268,7 +265,7 @@ export class MatTabGroup implements AfterContentInit, AfterContentChecked, OnDes
268
265
@Output ( ) readonly selectedTabChange : EventEmitter < MatTabChangeEvent > =
269
266
new EventEmitter < MatTabChangeEvent > ( true ) ;
270
267
271
- private _groupId : number ;
268
+ private _groupId : string ;
272
269
273
270
/** Whether the tab group is rendered on the server. */
274
271
protected _isServer : boolean = ! inject ( Platform ) . isBrowser ;
@@ -278,7 +275,7 @@ export class MatTabGroup implements AfterContentInit, AfterContentChecked, OnDes
278
275
constructor ( ) {
279
276
const defaultConfig = inject < MatTabsConfig > ( MAT_TABS_CONFIG , { optional : true } ) ;
280
277
281
- this . _groupId = nextId ++ ;
278
+ this . _groupId = inject ( _IdGenerator ) . getId ( 'mat-tab-group-' ) ;
282
279
this . animationDuration =
283
280
defaultConfig && defaultConfig . animationDuration ? defaultConfig . animationDuration : '500ms' ;
284
281
this . disablePagination =
@@ -492,12 +489,12 @@ export class MatTabGroup implements AfterContentInit, AfterContentChecked, OnDes
492
489
493
490
/** Returns a unique id for each tab label element */
494
491
_getTabLabelId ( i : number ) : string {
495
- return `mat-tab-label- ${ this . _groupId } -${ i } ` ;
492
+ return `${ this . _groupId } -label -${ i } ` ;
496
493
}
497
494
498
495
/** Returns a unique id for each tab content element */
499
496
_getTabContentId ( i : number ) : string {
500
- return `mat-tab-content- ${ this . _groupId } -${ i } ` ;
497
+ return `${ this . _groupId } -content -${ i } ` ;
501
498
}
502
499
503
500
/**
0 commit comments