Skip to content

Commit 4ef3d3f

Browse files
authored
refactor(cdk/overlay): remove deprecated APIs for v11 (#20511)
Removes most of the deprecated APIs for v11 under `cdk/overlay`. Note that these changes target primarily the breaking changes that should be easier to land. I've left out removing `ConnectedPositionStrategy` which has a separate PR (#17519), and `GlobalPositionStrategy.width` and `GlobalPositionStrategy.height`, because they'll be trickier to land. BREAKING CHANGES: * The `OVERLAY_PROVIDERS` constant has been removed. Import `OverlayModule` and use the providers directly instead. * `_platform` parameter of the `OverlayContainer` constructor is now required. * `_platform` parameter of the `FullscreenOverlayContainer` constructor is now required. * `_location` and `_outsideClickDispatcher` parameters of the `OverlayRef` constructor are now required. * `_location` and `_outsideClickDispatcher` parameters of the `Overlay` constructor are now required.
1 parent 5916800 commit 4ef3d3f

File tree

9 files changed

+24
-136
lines changed

9 files changed

+24
-136
lines changed

src/cdk/overlay/dispatchers/overlay-keyboard-dispatcher.ts

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,7 @@
77
*/
88

99
import {DOCUMENT} from '@angular/common';
10-
import {
11-
Inject,
12-
Injectable,
13-
InjectionToken,
14-
Optional,
15-
SkipSelf,
16-
} from '@angular/core';
10+
import {Inject, Injectable} from '@angular/core';
1711
import {OverlayReference} from '../overlay-reference';
1812
import {BaseOverlayDispatcher} from './base-overlay-dispatcher';
1913

@@ -67,25 +61,3 @@ export class OverlayKeyboardDispatcher extends BaseOverlayDispatcher {
6761
}
6862
}
6963
}
70-
71-
72-
/** @docs-private @deprecated @breaking-change 8.0.0 */
73-
export function OVERLAY_KEYBOARD_DISPATCHER_PROVIDER_FACTORY(
74-
dispatcher: OverlayKeyboardDispatcher, _document: any) {
75-
return dispatcher || new OverlayKeyboardDispatcher(_document);
76-
}
77-
78-
/** @docs-private @deprecated @breaking-change 8.0.0 */
79-
export const OVERLAY_KEYBOARD_DISPATCHER_PROVIDER = {
80-
// If there is already an OverlayKeyboardDispatcher available, use that.
81-
// Otherwise, provide a new one.
82-
provide: OverlayKeyboardDispatcher,
83-
deps: [
84-
[new Optional(), new SkipSelf(), OverlayKeyboardDispatcher],
85-
86-
// Coerce to `InjectionToken` so that the `deps` match the "shape"
87-
// of the type expected by Angular
88-
DOCUMENT as InjectionToken<any>
89-
],
90-
useFactory: OVERLAY_KEYBOARD_DISPATCHER_PROVIDER_FACTORY
91-
};

src/cdk/overlay/fullscreen-overlay-container.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,7 @@ export class FullscreenOverlayContainer extends OverlayContainer implements OnDe
2424
private _fullScreenEventName: string | undefined;
2525
private _fullScreenListener: () => void;
2626

27-
constructor(
28-
@Inject(DOCUMENT) _document: any,
29-
/**
30-
* @deprecated `platform` parameter to become required.
31-
* @breaking-change 10.0.0
32-
*/
33-
platform?: Platform) {
27+
constructor(@Inject(DOCUMENT) _document: any, platform: Platform) {
3428
super(_document, platform);
3529
}
3630

src/cdk/overlay/overlay-container.ts

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,7 @@
77
*/
88

99
import {DOCUMENT} from '@angular/common';
10-
import {
11-
Inject,
12-
Injectable,
13-
InjectionToken,
14-
OnDestroy,
15-
Optional,
16-
SkipSelf,
17-
} from '@angular/core';
10+
import {Inject, Injectable, OnDestroy} from '@angular/core';
1811
import {Platform} from '@angular/cdk/platform';
1912

2013
/**
@@ -30,13 +23,7 @@ export class OverlayContainer implements OnDestroy {
3023
protected _containerElement: HTMLElement;
3124
protected _document: Document;
3225

33-
constructor(
34-
@Inject(DOCUMENT) document: any,
35-
/**
36-
* @deprecated `platform` parameter to become required.
37-
* @breaking-change 10.0.0
38-
*/
39-
protected _platform?: Platform) {
26+
constructor(@Inject(DOCUMENT) document: any, protected _platform: Platform) {
4027
this._document = document;
4128
}
4229

@@ -67,11 +54,9 @@ export class OverlayContainer implements OnDestroy {
6754
* with the 'cdk-overlay-container' class on the document body.
6855
*/
6956
protected _createContainer(): void {
70-
// @breaking-change 10.0.0 Remove null check for `_platform`.
71-
const isBrowser = this._platform ? this._platform.isBrowser : typeof window !== 'undefined';
7257
const containerClass = 'cdk-overlay-container';
7358

74-
if (isBrowser || isTestEnvironment) {
59+
if (this._platform.isBrowser || isTestEnvironment) {
7560
const oppositePlatformContainers =
7661
this._document.querySelectorAll(`.${containerClass}[platform="server"], ` +
7762
`.${containerClass}[platform="test"]`);
@@ -97,29 +82,11 @@ export class OverlayContainer implements OnDestroy {
9782
// TODO(crisbeto): remove the test environment check once we have an overlay testing module.
9883
if (isTestEnvironment) {
9984
container.setAttribute('platform', 'test');
100-
} else if (!isBrowser) {
85+
} else if (!this._platform.isBrowser) {
10186
container.setAttribute('platform', 'server');
10287
}
10388

10489
this._document.body.appendChild(container);
10590
this._containerElement = container;
10691
}
10792
}
108-
109-
110-
/** @docs-private @deprecated @breaking-change 8.0.0 */
111-
export function OVERLAY_CONTAINER_PROVIDER_FACTORY(parentContainer: OverlayContainer,
112-
_document: any) {
113-
return parentContainer || new OverlayContainer(_document);
114-
}
115-
116-
/** @docs-private @deprecated @breaking-change 8.0.0 */
117-
export const OVERLAY_CONTAINER_PROVIDER = {
118-
// If there is already an OverlayContainer available, use that. Otherwise, provide a new one.
119-
provide: OverlayContainer,
120-
deps: [
121-
[new Optional(), new SkipSelf(), OverlayContainer],
122-
DOCUMENT as InjectionToken<any> // We need to use the InjectionToken somewhere to keep TS happy
123-
],
124-
useFactory: OVERLAY_CONTAINER_PROVIDER_FACTORY
125-
};

src/cdk/overlay/overlay-directives.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import {
3737
} from './position/flexible-connected-position-strategy';
3838
import {
3939
RepositionScrollStrategy,
40-
RepositionScrollStrategyConfig,
4140
ScrollStrategy,
4241
} from './scroll/index';
4342

@@ -74,12 +73,6 @@ const defaultPositionList: ConnectedPosition[] = [
7473
export const CDK_CONNECTED_OVERLAY_SCROLL_STRATEGY =
7574
new InjectionToken<() => ScrollStrategy>('cdk-connected-overlay-scroll-strategy');
7675

77-
/** @docs-private @deprecated @breaking-change 8.0.0 */
78-
export function CDK_CONNECTED_OVERLAY_SCROLL_STRATEGY_FACTORY(overlay: Overlay):
79-
() => ScrollStrategy {
80-
return (config?: RepositionScrollStrategyConfig) => overlay.scrollStrategies.reposition(config);
81-
}
82-
8376
/**
8477
* Directive applied to an element to make it usable as an origin for an Overlay using a
8578
* ConnectedPositionStrategy.

src/cdk/overlay/overlay-module.ts

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,13 @@
99
import {BidiModule} from '@angular/cdk/bidi';
1010
import {PortalModule} from '@angular/cdk/portal';
1111
import {ScrollingModule} from '@angular/cdk/scrolling';
12-
import {NgModule, Provider} from '@angular/core';
13-
import {OVERLAY_KEYBOARD_DISPATCHER_PROVIDER} from './dispatchers/overlay-keyboard-dispatcher';
12+
import {NgModule} from '@angular/core';
1413
import {Overlay} from './overlay';
15-
import {OVERLAY_CONTAINER_PROVIDER} from './overlay-container';
1614
import {
1715
CDK_CONNECTED_OVERLAY_SCROLL_STRATEGY_PROVIDER,
1816
CdkConnectedOverlay,
1917
CdkOverlayOrigin,
2018
} from './overlay-directives';
21-
import {OverlayPositionBuilder} from './position/overlay-position-builder';
2219

2320

2421
@NgModule({
@@ -31,17 +28,3 @@ import {OverlayPositionBuilder} from './position/overlay-position-builder';
3128
],
3229
})
3330
export class OverlayModule {}
34-
35-
36-
/**
37-
* @deprecated Use `OverlayModule` instead.
38-
* @breaking-change 8.0.0
39-
* @docs-private
40-
*/
41-
export const OVERLAY_PROVIDERS: Provider[] = [
42-
Overlay,
43-
OverlayPositionBuilder,
44-
OVERLAY_KEYBOARD_DISPATCHER_PROVIDER,
45-
OVERLAY_CONTAINER_PROVIDER,
46-
CDK_CONNECTED_OVERLAY_SCROLL_STRATEGY_PROVIDER,
47-
];

src/cdk/overlay/overlay-ref.ts

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,8 @@ export class OverlayRef implements PortalOutlet, OverlayReference {
6060
private _ngZone: NgZone,
6161
private _keyboardDispatcher: OverlayKeyboardDispatcher,
6262
private _document: Document,
63-
// @breaking-change 8.0.0 `_location` parameter to be made required.
64-
private _location?: Location,
65-
// @breaking-change 9.0.0 `_mouseClickDispatcher` parameter to be made required.
66-
private _outsideClickDispatcher?: OverlayOutsideClickDispatcher) {
63+
private _location: Location,
64+
private _outsideClickDispatcher: OverlayOutsideClickDispatcher) {
6765

6866
if (_config.scrollStrategy) {
6967
this._scrollStrategy = _config.scrollStrategy;
@@ -152,17 +150,11 @@ export class OverlayRef implements PortalOutlet, OverlayReference {
152150
// Track this overlay by the keyboard dispatcher
153151
this._keyboardDispatcher.add(this);
154152

155-
// @breaking-change 8.0.0 remove the null check for `_location`
156-
// once the constructor parameter is made required.
157-
if (this._config.disposeOnNavigation && this._location) {
153+
if (this._config.disposeOnNavigation) {
158154
this._locationChanges = this._location.subscribe(() => this.dispose());
159155
}
160156

161-
// @breaking-change 9.0.0 remove the null check for `_mouseClickDispatcher`
162-
if (this._outsideClickDispatcher) {
163-
this._outsideClickDispatcher.add(this);
164-
}
165-
157+
this._outsideClickDispatcher.add(this);
166158
return attachResult;
167159
}
168160

@@ -201,15 +193,8 @@ export class OverlayRef implements PortalOutlet, OverlayReference {
201193
// Keeping the host element in the DOM can cause scroll jank, because it still gets
202194
// rendered, even though it's transparent and unclickable which is why we remove it.
203195
this._detachContentWhenStable();
204-
205-
// Stop listening for location changes.
206196
this._locationChanges.unsubscribe();
207-
208-
// @breaking-change 9.0.0 remove the null check for `_outsideClickDispatcher`
209-
if (this._outsideClickDispatcher) {
210-
this._outsideClickDispatcher.remove(this);
211-
}
212-
197+
this._outsideClickDispatcher.remove(this);
213198
return detachmentResult;
214199
}
215200

@@ -230,11 +215,7 @@ export class OverlayRef implements PortalOutlet, OverlayReference {
230215
this._backdropClick.complete();
231216
this._keydownEvents.complete();
232217
this._outsidePointerEvents.complete();
233-
234-
// @breaking-change 9.0.0 remove the null check for `_outsideClickDispatcher`
235-
if (this._outsideClickDispatcher) {
236-
this._outsideClickDispatcher.remove(this);
237-
}
218+
this._outsideClickDispatcher.remove(this);
238219

239220
if (this._host && this._host.parentNode) {
240221
this._host.parentNode.removeChild(this._host);

src/cdk/overlay/overlay.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,8 @@ export class Overlay {
5555
private _ngZone: NgZone,
5656
@Inject(DOCUMENT) private _document: any,
5757
private _directionality: Directionality,
58-
// @breaking-change 8.0.0 `_location` parameter to be made required.
59-
private _location?: Location,
60-
// @breaking-change 9.0.0 `_outsideClickDispatcher` parameter to be made required.
61-
private _outsideClickDispatcher?: OverlayOutsideClickDispatcher) { }
58+
private _location: Location,
59+
private _outsideClickDispatcher: OverlayOutsideClickDispatcher) { }
6260

6361
/**
6462
* Creates an overlay.

src/cdk/schematics/ng-update/data/constructor-checks.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ export const constructorChecks: VersionChanges<ConstructorChecksUpgradeData> = {
2929
{
3030
pr: 'https://github.com/angular/components/pull/20572',
3131
changes: ['CdkTreeNodePadding']
32+
},
33+
{
34+
pr: 'https://github.com/angular/components/pull/20511',
35+
changes: ['OverlayContainer', 'FullscreenOverlayContainer', 'OverlayRef', 'Overlay']
3236
}
3337
],
3438
[TargetVersion.V10]: [

tools/public_api_guard/cdk/overlay.d.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,7 @@ export declare type FlexibleConnectedPositionStrategyOrigin = ElementRef | Eleme
152152
};
153153

154154
export declare class FullscreenOverlayContainer extends OverlayContainer implements OnDestroy {
155-
constructor(_document: any,
156-
platform?: Platform);
155+
constructor(_document: any, platform: Platform);
157156
protected _createContainer(): void;
158157
getFullscreenElement(): Element;
159158
ngOnDestroy(): void;
@@ -191,15 +190,13 @@ export interface OriginConnectionPosition {
191190
export declare class Overlay {
192191
scrollStrategies: ScrollStrategyOptions;
193192
constructor(
194-
scrollStrategies: ScrollStrategyOptions, _overlayContainer: OverlayContainer, _componentFactoryResolver: ComponentFactoryResolver, _positionBuilder: OverlayPositionBuilder, _keyboardDispatcher: OverlayKeyboardDispatcher, _injector: Injector, _ngZone: NgZone, _document: any, _directionality: Directionality, _location?: Location | undefined, _outsideClickDispatcher?: OverlayOutsideClickDispatcher | undefined);
193+
scrollStrategies: ScrollStrategyOptions, _overlayContainer: OverlayContainer, _componentFactoryResolver: ComponentFactoryResolver, _positionBuilder: OverlayPositionBuilder, _keyboardDispatcher: OverlayKeyboardDispatcher, _injector: Injector, _ngZone: NgZone, _document: any, _directionality: Directionality, _location: Location, _outsideClickDispatcher: OverlayOutsideClickDispatcher);
195194
create(config?: OverlayConfig): OverlayRef;
196195
position(): OverlayPositionBuilder;
197196
static ɵfac: i0.ɵɵFactoryDef<Overlay, never>;
198197
static ɵprov: i0.ɵɵInjectableDef<Overlay>;
199198
}
200199

201-
export declare const OVERLAY_PROVIDERS: Provider[];
202-
203200
export declare class OverlayConfig {
204201
backdropClass?: string | string[];
205202
direction?: Direction | Directionality;
@@ -225,9 +222,8 @@ export interface OverlayConnectionPosition {
225222
export declare class OverlayContainer implements OnDestroy {
226223
protected _containerElement: HTMLElement;
227224
protected _document: Document;
228-
protected _platform?: Platform | undefined;
229-
constructor(document: any,
230-
_platform?: Platform | undefined);
225+
protected _platform: Platform;
226+
constructor(document: any, _platform: Platform);
231227
protected _createContainer(): void;
232228
getContainerElement(): HTMLElement;
233229
ngOnDestroy(): void;
@@ -271,7 +267,7 @@ export declare class OverlayRef implements PortalOutlet, OverlayReference {
271267
get backdropElement(): HTMLElement | null;
272268
get hostElement(): HTMLElement;
273269
get overlayElement(): HTMLElement;
274-
constructor(_portalOutlet: PortalOutlet, _host: HTMLElement, _pane: HTMLElement, _config: ImmutableObject<OverlayConfig>, _ngZone: NgZone, _keyboardDispatcher: OverlayKeyboardDispatcher, _document: Document, _location?: Location | undefined, _outsideClickDispatcher?: OverlayOutsideClickDispatcher | undefined);
270+
constructor(_portalOutlet: PortalOutlet, _host: HTMLElement, _pane: HTMLElement, _config: ImmutableObject<OverlayConfig>, _ngZone: NgZone, _keyboardDispatcher: OverlayKeyboardDispatcher, _document: Document, _location: Location, _outsideClickDispatcher: OverlayOutsideClickDispatcher);
275271
addPanelClass(classes: string | string[]): void;
276272
attach<T>(portal: ComponentPortal<T>): ComponentRef<T>;
277273
attach<T>(portal: TemplatePortal<T>): EmbeddedViewRef<T>;

0 commit comments

Comments
 (0)