@@ -18,6 +18,7 @@ import {
1818 EnvironmentInjector ,
1919 inject ,
2020} from '@angular/core' ;
21+ import { _IdGenerator } from '@angular/cdk/a11y' ;
2122import { _CdkPrivateStyleLoader } from '@angular/cdk/private' ;
2223import { OverlayKeyboardDispatcher } from './dispatchers/overlay-keyboard-dispatcher' ;
2324import { OverlayOutsideClickDispatcher } from './dispatchers/overlay-outside-click-dispatcher' ;
@@ -27,9 +28,6 @@ import {OverlayRef} from './overlay-ref';
2728import { OverlayPositionBuilder } from './position/overlay-position-builder' ;
2829import { ScrollStrategyOptions } from './scroll/index' ;
2930
30- /** Next overlay unique ID. */
31- let nextUniqueId = 0 ;
32-
3331/**
3432 * Service to create Overlays. Overlays are dynamically added pieces of floating UI, meant to be
3533 * used as a low-level building block for other components. Dialogs, tooltips, menus,
@@ -51,6 +49,7 @@ export class Overlay {
5149 private _location = inject ( Location ) ;
5250 private _outsideClickDispatcher = inject ( OverlayOutsideClickDispatcher ) ;
5351 private _animationsModuleType = inject ( ANIMATION_MODULE_TYPE , { optional : true } ) ;
52+ private _idGenerator = inject ( _IdGenerator ) ;
5453
5554 private _appRef : ApplicationRef ;
5655 private _styleLoader = inject ( _CdkPrivateStyleLoader ) ;
@@ -106,7 +105,7 @@ export class Overlay {
106105 private _createPaneElement ( host : HTMLElement ) : HTMLElement {
107106 const pane = this . _document . createElement ( 'div' ) ;
108107
109- pane . id = ` cdk-overlay-${ nextUniqueId ++ } ` ;
108+ pane . id = this . _idGenerator . getId ( ' cdk-overlay-' ) ;
110109 pane . classList . add ( 'cdk-overlay-pane' ) ;
111110 host . appendChild ( pane ) ;
112111
0 commit comments