Skip to content

Commit d9b91de

Browse files
committed
refactor(material/dialog): switch to tree shakeable overlay APIs
Reworks the module to use the new tree-shakeable APIs for creating overlays.
1 parent 568abd5 commit d9b91de

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

src/material/dialog/dialog.spec.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {FocusMonitor, FocusOrigin} from '@angular/cdk/a11y';
22
import {Directionality} from '@angular/cdk/bidi';
33
import {A, ESCAPE} from '@angular/cdk/keycodes';
4-
import {Overlay, OverlayContainer, ScrollStrategy} from '@angular/cdk/overlay';
4+
import {createCloseScrollStrategy, OverlayContainer, ScrollStrategy} from '@angular/cdk/overlay';
55
import {_supportsShadowDom} from '@angular/cdk/platform';
66
import {ScrollDispatcher} from '@angular/cdk/scrolling';
77
import {
@@ -238,10 +238,9 @@ describe('MatDialog', () => {
238238
}));
239239

240240
it('should dispatch the beforeClosed and afterClosed events when the overlay is detached externally', fakeAsync(() => {
241-
const overlay = TestBed.inject(Overlay);
242241
const dialogRef = dialog.open(PizzaMsg, {
243242
viewContainerRef: testViewContainerRef,
244-
scrollStrategy: overlay.scrollStrategies.close(),
243+
scrollStrategy: createCloseScrollStrategy(TestBed.inject(Injector)),
245244
});
246245
const beforeClosedCallback = jasmine.createSpy('beforeClosed callback');
247246
const afterCloseCallback = jasmine.createSpy('afterClosed callback');

src/material/dialog/dialog.ts

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

9-
import {ComponentType, Overlay, ScrollStrategy} from '@angular/cdk/overlay';
9+
import {
10+
ComponentType,
11+
createBlockScrollStrategy,
12+
createGlobalPositionStrategy,
13+
ScrollStrategy,
14+
} from '@angular/cdk/overlay';
1015
import {
1116
ComponentRef,
1217
Injectable,
1318
InjectionToken,
19+
Injector,
1420
OnDestroy,
1521
TemplateRef,
1622
Type,
@@ -39,8 +45,8 @@ export const MAT_DIALOG_SCROLL_STRATEGY = new InjectionToken<() => ScrollStrateg
3945
{
4046
providedIn: 'root',
4147
factory: () => {
42-
const overlay = inject(Overlay);
43-
return () => overlay.scrollStrategies.block();
48+
const injector = inject(Injector);
49+
return () => createBlockScrollStrategy(injector);
4450
},
4551
},
4652
);
@@ -50,11 +56,11 @@ export const MAT_DIALOG_SCROLL_STRATEGY = new InjectionToken<() => ScrollStrateg
5056
*/
5157
@Injectable({providedIn: 'root'})
5258
export class MatDialog implements OnDestroy {
53-
private _overlay = inject(Overlay);
5459
private _defaultOptions = inject<MatDialogConfig>(MAT_DIALOG_DEFAULT_OPTIONS, {optional: true});
5560
private _scrollStrategy = inject(MAT_DIALOG_SCROLL_STRATEGY);
5661
private _parentDialog = inject(MatDialog, {optional: true, skipSelf: true});
5762
private _idGenerator = inject(_IdGenerator);
63+
private _injector = inject(Injector);
5864
protected _dialog = inject(Dialog);
5965
private _animationsDisabled = _animationsDisabled();
6066

@@ -138,7 +144,9 @@ export class MatDialog implements OnDestroy {
138144

139145
const cdkRef = this._dialog.open<R, D, T>(componentOrTemplateRef, {
140146
...config,
141-
positionStrategy: this._overlay.position().global().centerHorizontally().centerVertically(),
147+
positionStrategy: createGlobalPositionStrategy(this._injector)
148+
.centerHorizontally()
149+
.centerVertically(),
142150
// Disable closing since we need to sync it up to the animation ourselves.
143151
disableClose: true,
144152
// Closing is tied to our animation so the close predicate has to be implemented separately.

0 commit comments

Comments
 (0)