6
6
* found in the LICENSE file at https://angular.dev/license
7
7
*/
8
8
9
- import { AriaDescriber , InteractivityChecker } from '@angular/cdk/a11y' ;
9
+ import { _IdGenerator , AriaDescriber , InteractivityChecker } from '@angular/cdk/a11y' ;
10
10
import { DOCUMENT } from '@angular/common' ;
11
11
import {
12
12
booleanAttribute ,
@@ -26,8 +26,6 @@ import {
26
26
import { ThemePalette } from '@angular/material/core' ;
27
27
import { _CdkPrivateStyleLoader , _VisuallyHiddenLoader } from '@angular/cdk/private' ;
28
28
29
- let nextId = 0 ;
30
-
31
29
/** Allowed position options for matBadgePosition */
32
30
export type MatBadgePosition =
33
31
| 'above after'
@@ -79,6 +77,7 @@ export class MatBadge implements OnInit, OnDestroy {
79
77
private _ariaDescriber = inject ( AriaDescriber ) ;
80
78
private _renderer = inject ( Renderer2 ) ;
81
79
private _animationMode = inject ( ANIMATION_MODULE_TYPE , { optional : true } ) ;
80
+ private _idGenerator = inject ( _IdGenerator ) ;
82
81
83
82
/**
84
83
* Theme color of the badge. This API is supported in M2 themes only, it
@@ -135,9 +134,6 @@ export class MatBadge implements OnInit, OnDestroy {
135
134
/** Whether the badge is hidden. */
136
135
@Input ( { alias : 'matBadgeHidden' , transform : booleanAttribute } ) hidden : boolean ;
137
136
138
- /** Unique id for the badge */
139
- _id : number = nextId ++ ;
140
-
141
137
/** Visible badge element. */
142
138
private _badgeElement : HTMLElement | undefined ;
143
139
@@ -236,7 +232,7 @@ export class MatBadge implements OnInit, OnDestroy {
236
232
const badgeElement = this . _renderer . createElement ( 'span' ) ;
237
233
const activeClass = 'mat-badge-active' ;
238
234
239
- badgeElement . setAttribute ( 'id' , ` mat-badge-content-${ this . _id } ` ) ;
235
+ badgeElement . setAttribute ( 'id' , this . _idGenerator . getId ( ' mat-badge-content-' ) ) ;
240
236
241
237
// The badge is aria-hidden because we don't want it to appear in the page's navigation
242
238
// flow. Instead, we use the badge to describe the decorated element with aria-describedby.
0 commit comments