|
6 | 6 | * found in the LICENSE file at https://angular.dev/license
|
7 | 7 | */
|
8 | 8 |
|
9 |
| -import {FocusMonitor} from '@angular/cdk/a11y'; |
| 9 | +import {_IdGenerator, FocusMonitor} from '@angular/cdk/a11y'; |
10 | 10 | import {SelectionModel} from '@angular/cdk/collections';
|
11 | 11 | import {DOWN_ARROW, LEFT_ARROW, RIGHT_ARROW, UP_ARROW, SPACE, ENTER} from '@angular/cdk/keycodes';
|
12 | 12 | import {
|
@@ -104,9 +104,6 @@ export const MAT_BUTTON_TOGGLE_GROUP_VALUE_ACCESSOR: any = {
|
104 | 104 | multi: true,
|
105 | 105 | };
|
106 | 106 |
|
107 |
| -// Counter used to generate unique IDs. |
108 |
| -let uniqueIdCounter = 0; |
109 |
| - |
110 | 107 | /** Change event object emitted by button toggle. */
|
111 | 108 | export class MatButtonToggleChange {
|
112 | 109 | constructor(
|
@@ -181,7 +178,7 @@ export class MatButtonToggleGroup implements ControlValueAccessor, OnInit, After
|
181 | 178 | this._name = value;
|
182 | 179 | this._markButtonsForCheck();
|
183 | 180 | }
|
184 |
| - private _name = `mat-button-toggle-group-${uniqueIdCounter++}`; |
| 181 | + private _name = inject(_IdGenerator).getId('mat-button-toggle-group-'); |
185 | 182 |
|
186 | 183 | /** Whether the toggle group is vertical. */
|
187 | 184 | @Input({transform: booleanAttribute}) vertical: boolean;
|
@@ -562,6 +559,7 @@ export class MatButtonToggle implements OnInit, AfterViewInit, OnDestroy {
|
562 | 559 | private _changeDetectorRef = inject(ChangeDetectorRef);
|
563 | 560 | private _elementRef = inject<ElementRef<HTMLElement>>(ElementRef);
|
564 | 561 | private _focusMonitor = inject(FocusMonitor);
|
| 562 | + private _idGenerator = inject(_IdGenerator); |
565 | 563 |
|
566 | 564 | private _checked = false;
|
567 | 565 |
|
@@ -685,7 +683,7 @@ export class MatButtonToggle implements OnInit, AfterViewInit, OnDestroy {
|
685 | 683 |
|
686 | 684 | ngOnInit() {
|
687 | 685 | const group = this.buttonToggleGroup;
|
688 |
| - this.id = this.id || `mat-button-toggle-${uniqueIdCounter++}`; |
| 686 | + this.id = this.id || this._idGenerator.getId('mat-button-toggle-'); |
689 | 687 |
|
690 | 688 | if (group) {
|
691 | 689 | if (group._isPrechecked(this)) {
|
|
0 commit comments