Skip to content

Commit c1dd952

Browse files
committed
refactor(cdk/dialog): switch to tree shakeable overlay APIs
Reworks the module to use the new tree-shakeable APIs for creating overlays.
1 parent 93e2aab commit c1dd952

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

src/cdk/dialog/dialog-injectors.ts

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

9-
import {InjectionToken, inject} from '@angular/core';
10-
import {Overlay, ScrollStrategy} from '../overlay';
9+
import {InjectionToken, Injector, inject} from '@angular/core';
10+
import {createBlockScrollStrategy, ScrollStrategy} from '../overlay';
1111
import {DialogConfig} from './dialog-config';
1212

1313
/** Injection token for the Dialog's ScrollStrategy. */
@@ -16,8 +16,8 @@ export const DIALOG_SCROLL_STRATEGY = new InjectionToken<() => ScrollStrategy>(
1616
{
1717
providedIn: 'root',
1818
factory: () => {
19-
const overlay = inject(Overlay);
20-
return () => overlay.scrollStrategies.block();
19+
const injector = inject(Injector);
20+
return () => createBlockScrollStrategy(injector);
2121
},
2222
},
2323
);

src/cdk/dialog/dialog.spec.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import {Directionality} from '../bidi';
22
import {A, ESCAPE} from '../keycodes';
3-
import {Overlay, OverlayContainer, ScrollDispatcher} from '../overlay';
3+
import {
4+
createCloseScrollStrategy,
5+
createGlobalPositionStrategy,
6+
OverlayContainer,
7+
ScrollDispatcher,
8+
} from '../overlay';
49
import {_supportsShadowDom} from '../platform';
510
import {createKeyboardEvent, dispatchEvent, dispatchKeyboardEvent} from '../testing/private';
611
import {Location} from '@angular/common';
@@ -37,7 +42,6 @@ describe('Dialog', () => {
3742
let testViewContainerRef: ViewContainerRef;
3843
let viewContainerFixture: ComponentFixture<ComponentWithChildViewContainer>;
3944
let mockLocation: SpyLocation;
40-
let overlay: Overlay;
4145
let scrolledSubject = new Subject();
4246

4347
beforeEach(fakeAsync(() => {
@@ -66,7 +70,6 @@ describe('Dialog', () => {
6670

6771
dialog = TestBed.inject(Dialog);
6872
mockLocation = TestBed.inject(Location) as SpyLocation;
69-
overlay = TestBed.inject(Overlay);
7073
overlayContainerElement = TestBed.inject(OverlayContainer).getContainerElement();
7174

7275
viewContainerFixture = TestBed.createComponent(ComponentWithChildViewContainer);
@@ -452,7 +455,7 @@ describe('Dialog', () => {
452455

453456
it('should be able to customize the position strategy', () => {
454457
dialog.open(PizzaMsg, {
455-
positionStrategy: overlay.position().global().top('100px'),
458+
positionStrategy: createGlobalPositionStrategy(TestBed.inject(Injector)).top('100px'),
456459
});
457460

458461
viewContainerFixture.detectChanges();
@@ -555,12 +558,13 @@ describe('Dialog', () => {
555558

556559
it('should close the dialog when detached externally', fakeAsync(() => {
557560
const closeSpy = jasmine.createSpy('closed');
561+
const injector = TestBed.inject(Injector);
558562
dialog
559-
.open(PizzaMsg, {scrollStrategy: overlay.scrollStrategies.close()})
563+
.open(PizzaMsg, {scrollStrategy: createCloseScrollStrategy(injector)})
560564
.closed.subscribe(closeSpy);
561565
viewContainerFixture.detectChanges();
562566
dialog
563-
.open(PizzaMsg, {scrollStrategy: overlay.scrollStrategies.close()})
567+
.open(PizzaMsg, {scrollStrategy: createCloseScrollStrategy(injector)})
564568
.closed.subscribe(closeSpy);
565569
viewContainerFixture.detectChanges();
566570

src/cdk/dialog/dialog.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,14 @@ import {Observable, Subject, defer} from 'rxjs';
2222
import {startWith} from 'rxjs/operators';
2323
import {_IdGenerator} from '../a11y';
2424
import {Direction, Directionality} from '../bidi';
25-
import {ComponentType, Overlay, OverlayConfig, OverlayContainer, OverlayRef} from '../overlay';
25+
import {
26+
ComponentType,
27+
createGlobalPositionStrategy,
28+
createOverlayRef,
29+
OverlayConfig,
30+
OverlayContainer,
31+
OverlayRef,
32+
} from '../overlay';
2633
import {BasePortalOutlet, ComponentPortal, TemplatePortal} from '../portal';
2734
import {DialogConfig} from './dialog-config';
2835
import {DialogRef} from './dialog-ref';
@@ -47,7 +54,6 @@ function getDirectionality(value: Direction): Directionality {
4754

4855
@Injectable({providedIn: 'root'})
4956
export class Dialog implements OnDestroy {
50-
private _overlay = inject(Overlay);
5157
private _injector = inject(Injector);
5258
private _defaultOptions = inject<DialogConfig>(DEFAULT_DIALOG_CONFIG, {optional: true});
5359
private _parentDialog = inject(Dialog, {optional: true, skipSelf: true});
@@ -131,7 +137,7 @@ export class Dialog implements OnDestroy {
131137
}
132138

133139
const overlayConfig = this._getOverlayConfig(config);
134-
const overlayRef = this._overlay.create(overlayConfig);
140+
const overlayRef = createOverlayRef(this._injector, overlayConfig);
135141
const dialogRef = new DialogRef(overlayRef, config);
136142
const dialogContainer = this._attachContainer(overlayRef, dialogRef, config);
137143

@@ -195,7 +201,7 @@ export class Dialog implements OnDestroy {
195201
const state = new OverlayConfig({
196202
positionStrategy:
197203
config.positionStrategy ||
198-
this._overlay.position().global().centerHorizontally().centerVertically(),
204+
createGlobalPositionStrategy(this._injector).centerHorizontally().centerVertically(),
199205
scrollStrategy: config.scrollStrategy || this._scrollStrategy(),
200206
panelClass: config.panelClass,
201207
hasBackdrop: config.hasBackdrop,

0 commit comments

Comments
 (0)