Skip to content

Commit 7f22090

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

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/material/select/select.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ describe('MatSelect', () => {
220220
fixture.detectChanges();
221221
const hint = fixture.debugElement.query(By.css('mat-hint')).nativeElement;
222222
expect(select.getAttribute('aria-describedby')).toBe(hint.getAttribute('id'));
223-
expect(select.getAttribute('aria-describedby')).toMatch(/^mat-mdc-hint-\d+$/);
223+
expect(select.getAttribute('aria-describedby')).toMatch(/^mat-mdc-hint-\w+\d+$/);
224224
});
225225

226226
it('should support user binding to `aria-describedby`', () => {

src/material/select/select.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
import {
10+
_IdGenerator,
1011
ActiveDescendantKeyManager,
1112
addAriaReferencedId,
1213
LiveAnnouncer,
@@ -96,8 +97,6 @@ import {
9697
} from './select-errors';
9798
import {NgClass} from '@angular/common';
9899

99-
let nextUniqueId = 0;
100-
101100
/** Injection token that determines the scroll handling while a select is open. */
102101
export const MAT_SELECT_SCROLL_STRATEGY = new InjectionToken<() => ScrollStrategy>(
103102
'mat-select-scroll-strategy',
@@ -215,6 +214,7 @@ export class MatSelect
215214
protected _changeDetectorRef = inject(ChangeDetectorRef);
216215
readonly _elementRef = inject(ElementRef);
217216
private _dir = inject(Directionality, {optional: true});
217+
private _idGenerator = inject(_IdGenerator);
218218
protected _parentFormField = inject<MatFormField>(MAT_FORM_FIELD, {optional: true});
219219
ngControl = inject(NgControl, {self: true, optional: true})!;
220220
private _liveAnnouncer = inject(LiveAnnouncer);
@@ -312,7 +312,7 @@ export class MatSelect
312312
private _compareWith = (o1: any, o2: any) => o1 === o2;
313313

314314
/** Unique id for this input. */
315-
private _uid = `mat-select-${nextUniqueId++}`;
315+
private _uid = this._idGenerator.getId('mat-select-');
316316

317317
/** Current `aria-labelledby` value for the select trigger. */
318318
private _triggerAriaLabelledBy: string | null = null;
@@ -367,7 +367,7 @@ export class MatSelect
367367
_onTouched = () => {};
368368

369369
/** ID for the DOM node containing the select's value. */
370-
_valueId = `mat-select-value-${nextUniqueId++}`;
370+
_valueId = this._idGenerator.getId('mat-select-value-');
371371

372372
/** Emits when the panel element is finished transforming in. */
373373
readonly _panelDoneAnimatingStream = new Subject<string>();

0 commit comments

Comments
 (0)