Skip to content

Commit b5226c2

Browse files
committed
refactor(material/autocomplete): use ID generator
Switches to using the ID generator service to create unique IDs.
1 parent 855d82f commit b5226c2

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

src/material/autocomplete/autocomplete.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,11 @@ import {
3333
MatOption,
3434
ThemePalette,
3535
} from '@angular/material/core';
36-
import {ActiveDescendantKeyManager} from '@angular/cdk/a11y';
36+
import {_IdGenerator, ActiveDescendantKeyManager} from '@angular/cdk/a11y';
3737
import {Platform} from '@angular/cdk/platform';
3838
import {panelAnimation} from './animations';
3939
import {Subscription} from 'rxjs';
4040

41-
/**
42-
* Autocomplete IDs need to be unique across components, so this counter exists outside of
43-
* the component definition.
44-
*/
45-
let _uniqueAutocompleteIdCounter = 0;
46-
4741
/** Event object that is emitted when an autocomplete option is selected. */
4842
export class MatAutocompleteSelectedEvent {
4943
constructor(
@@ -247,7 +241,7 @@ export class MatAutocomplete implements AfterContentInit, OnDestroy {
247241
}
248242

249243
/** Unique ID to be used by autocomplete trigger's "aria-owns" property. */
250-
id: string = `mat-autocomplete-${_uniqueAutocompleteIdCounter++}`;
244+
id: string = inject(_IdGenerator).getId('mat-autocomplete-');
251245

252246
/**
253247
* Tells any descendant `mat-optgroup` to use the inert a11y pattern.

0 commit comments

Comments
 (0)