Skip to content

Commit 557d55f

Browse files
committed
refactor(material/radio): use ID generator
Switches to using the ID generator service to create unique IDs.
1 parent 416c64e commit 557d55f

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/material/radio/radio.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9-
import {FocusMonitor, FocusOrigin} from '@angular/cdk/a11y';
9+
import {_IdGenerator, FocusMonitor, FocusOrigin} from '@angular/cdk/a11y';
1010
import {UniqueSelectionDispatcher} from '@angular/cdk/collections';
1111
import {
1212
ANIMATION_MODULE_TYPE,
@@ -47,9 +47,6 @@ import {
4747
import {Subscription} from 'rxjs';
4848
import {_CdkPrivateStyleLoader} from '@angular/cdk/private';
4949

50-
// Increasing integer for generating unique ids for radio components.
51-
let nextUniqueId = 0;
52-
5350
/** Change event object emitted by radio button and radio group. */
5451
export class MatRadioChange {
5552
constructor(
@@ -129,7 +126,7 @@ export class MatRadioGroup implements AfterContentInit, OnDestroy, ControlValueA
129126
private _value: any = null;
130127

131128
/** The HTML name attribute applied to radio buttons in this group. */
132-
private _name: string = `mat-radio-group-${nextUniqueId++}`;
129+
private _name: string = inject(_IdGenerator).getId('mat-radio-group-');
133130

134131
/** The currently selected radio button. Should match value. */
135132
private _selected: MatRadioButton | null = null;
@@ -422,7 +419,7 @@ export class MatRadioButton implements OnInit, AfterViewInit, DoCheck, OnDestroy
422419
});
423420

424421
private _ngZone = inject(NgZone);
425-
private _uniqueId: string = `mat-radio-${++nextUniqueId}`;
422+
private _uniqueId: string = inject(_IdGenerator).getId('mat-radio-');
426423

427424
/** The unique ID for the radio button. */
428425
@Input() id: string = this._uniqueId;

0 commit comments

Comments
 (0)