Skip to content

Commit af71c31

Browse files
committed
refactor(cdk/overlay): use ID generator
Switches to using the ID generator service to create unique IDs.
1 parent 89ed2ef commit af71c31

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/cdk/overlay/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ ng_module(
2323
],
2424
deps = [
2525
"//src:dev_mode_types",
26+
"//src/cdk/a11y",
2627
"//src/cdk/bidi",
2728
"//src/cdk/coercion",
2829
"//src/cdk/keycodes",

src/cdk/overlay/overlay.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
EnvironmentInjector,
1919
inject,
2020
} from '@angular/core';
21+
import {_IdGenerator} from '@angular/cdk/a11y';
2122
import {_CdkPrivateStyleLoader} from '@angular/cdk/private';
2223
import {OverlayKeyboardDispatcher} from './dispatchers/overlay-keyboard-dispatcher';
2324
import {OverlayOutsideClickDispatcher} from './dispatchers/overlay-outside-click-dispatcher';
@@ -27,9 +28,6 @@ import {OverlayRef} from './overlay-ref';
2728
import {OverlayPositionBuilder} from './position/overlay-position-builder';
2829
import {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

Comments
 (0)