Skip to content

Commit d987587

Browse files
authored
refactor(cdk/scrolling): remove deprecated APIs for v11 (#20454)
BREAKING CHANGES: * The `document` parameter of the `ScrollDispatcher` constructor is now required. * The `document` parameter of the `ViewportRuler` constructor is now required. * The `viewportRuler` parameter of the `CdkVirtualScrollViewport` constructor is now required. Also bumps two autocomplete APIs that were only marked as deprecated 10 days ago to v12 instead of v11.
1 parent 58e0c48 commit d987587

File tree

6 files changed

+24
-42
lines changed

6 files changed

+24
-42
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ export type ConstructorChecksUpgradeData = string;
1717
* automatically through type checking.
1818
*/
1919
export const constructorChecks: VersionChanges<ConstructorChecksUpgradeData> = {
20+
[TargetVersion.V11]: [
21+
{
22+
pr: 'https://github.com/angular/components/pull/20454',
23+
changes: ['ScrollDispatcher', 'ViewportRuler', 'CdkVirtualScrollViewport']
24+
}
25+
],
2026
[TargetVersion.V10]: [
2127
{
2228
pr: 'https://github.com/angular/components/pull/19347',

src/cdk/scrolling/scroll-dispatcher.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,11 @@ export const DEFAULT_SCROLL_TIME = 20;
2323
@Injectable({providedIn: 'root'})
2424
export class ScrollDispatcher implements OnDestroy {
2525
/** Used to reference correct document/window */
26-
protected _document?: Document;
26+
protected _document: Document;
2727

2828
constructor(private _ngZone: NgZone,
2929
private _platform: Platform,
30-
/** @breaking-change 11.0.0 make document required */
31-
@Optional() @Inject(DOCUMENT) document?: any) {
30+
@Optional() @Inject(DOCUMENT) document: any) {
3231
this._document = document;
3332
}
3433

@@ -144,15 +143,9 @@ export class ScrollDispatcher implements OnDestroy {
144143
return scrollingContainers;
145144
}
146145

147-
/** Access injected document if available or fallback to global document reference */
148-
private _getDocument(): Document {
149-
return this._document || document;
150-
}
151-
152146
/** Use defaultView of injected document if available or fallback to global window reference */
153147
private _getWindow(): Window {
154-
const doc = this._getDocument();
155-
return doc.defaultView || window;
148+
return this._document.defaultView || window;
156149
}
157150

158151
/** Returns true if the element is contained within the provided Scrollable. */

src/cdk/scrolling/viewport-ruler.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,11 @@ export class ViewportRuler implements OnDestroy {
3939
}
4040

4141
/** Used to reference correct document/window */
42-
protected _document?: Document;
42+
protected _document: Document;
4343

4444
constructor(private _platform: Platform,
4545
ngZone: NgZone,
46-
/** @breaking-change 11.0.0 make document required */
47-
@Optional() @Inject(DOCUMENT) document?: any) {
46+
@Optional() @Inject(DOCUMENT) document: any) {
4847
this._document = document;
4948

5049
ngZone.runOutsideAngular(() => {
@@ -127,7 +126,7 @@ export class ViewportRuler implements OnDestroy {
127126
// `scrollTop` and `scrollLeft` is inconsistent. However, using the bounding rect of
128127
// `document.documentElement` works consistently, where the `top` and `left` values will
129128
// equal negative the scroll position.
130-
const document = this._getDocument();
129+
const document = this._document;
131130
const window = this._getWindow();
132131
const documentElement = document.documentElement!;
133132
const documentRect = documentElement.getBoundingClientRect();
@@ -149,15 +148,9 @@ export class ViewportRuler implements OnDestroy {
149148
return throttleTime > 0 ? this._change.pipe(auditTime(throttleTime)) : this._change;
150149
}
151150

152-
/** Access injected document if available or fallback to global document reference */
153-
private _getDocument(): Document {
154-
return this._document || document;
155-
}
156-
157151
/** Use defaultView of injected document if available or fallback to global window reference */
158152
private _getWindow(): Window {
159-
const doc = this._getDocument();
160-
return doc.defaultView || window;
153+
return this._document.defaultView || window;
161154
}
162155

163156
/** Updates the cached viewport size. */

src/cdk/scrolling/virtual-scroll-viewport.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -159,23 +159,16 @@ export class CdkVirtualScrollViewport extends CdkScrollable implements OnInit, O
159159
private _scrollStrategy: VirtualScrollStrategy,
160160
@Optional() dir: Directionality,
161161
scrollDispatcher: ScrollDispatcher,
162-
/**
163-
* @deprecated `viewportRuler` parameter to become required.
164-
* @breaking-change 11.0.0
165-
*/
166-
viewportRuler?: ViewportRuler) {
162+
viewportRuler: ViewportRuler) {
167163
super(elementRef, scrollDispatcher, ngZone, dir);
168164

169165
if (!_scrollStrategy && (typeof ngDevMode === 'undefined' || ngDevMode)) {
170166
throw Error('Error: cdk-virtual-scroll-viewport requires the "itemSize" property to be set.');
171167
}
172168

173-
// @breaking-change 11.0.0 Remove null check for `viewportRuler`.
174-
if (viewportRuler) {
175-
this._viewportChanges = viewportRuler.change().subscribe(() => {
176-
this.checkViewportSize();
177-
});
178-
}
169+
this._viewportChanges = viewportRuler.change().subscribe(() => {
170+
this.checkViewportSize();
171+
});
179172
}
180173

181174
ngOnInit() {

src/material/autocomplete/autocomplete-trigger.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,14 @@ import {_MatAutocompleteOriginBase} from './autocomplete-origin';
6666
/**
6767
* The height of each autocomplete option.
6868
* @deprecated No longer being used. To be removed.
69-
* @breaking-change 11.0.0
69+
* @breaking-change 12.0.0
7070
*/
7171
export const AUTOCOMPLETE_OPTION_HEIGHT = 48;
7272

7373
/**
7474
* The total height of the autocomplete panel.
7575
* @deprecated No longer being used. To be removed.
76-
* @breaking-change 11.0.0
76+
* @breaking-change 12.0.0
7777
*/
7878
export const AUTOCOMPLETE_PANEL_HEIGHT = 256;
7979

tools/public_api_guard/cdk/scrolling.d.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,7 @@ export declare class CdkVirtualScrollViewport extends CdkScrollable implements O
124124
set orientation(orientation: 'horizontal' | 'vertical');
125125
renderedRangeStream: Observable<ListRange>;
126126
scrolledIndexChange: Observable<number>;
127-
constructor(elementRef: ElementRef<HTMLElement>, _changeDetectorRef: ChangeDetectorRef, ngZone: NgZone, _scrollStrategy: VirtualScrollStrategy, dir: Directionality, scrollDispatcher: ScrollDispatcher,
128-
viewportRuler?: ViewportRuler);
127+
constructor(elementRef: ElementRef<HTMLElement>, _changeDetectorRef: ChangeDetectorRef, ngZone: NgZone, _scrollStrategy: VirtualScrollStrategy, dir: Directionality, scrollDispatcher: ScrollDispatcher, viewportRuler: ViewportRuler);
129128
attach(forOf: CdkVirtualScrollRepeater<any>): void;
130129
checkViewportSize(): void;
131130
detach(): void;
@@ -167,11 +166,10 @@ export declare class FixedSizeVirtualScrollStrategy implements VirtualScrollStra
167166
}
168167

169168
export declare class ScrollDispatcher implements OnDestroy {
170-
protected _document?: Document;
169+
protected _document: Document;
171170
_globalSubscription: Subscription | null;
172171
scrollContainers: Map<CdkScrollable, Subscription>;
173-
constructor(_ngZone: NgZone, _platform: Platform,
174-
document?: any);
172+
constructor(_ngZone: NgZone, _platform: Platform, document: any);
175173
ancestorScrolled(elementRef: ElementRef, auditTimeInMs?: number): Observable<CdkScrollable | void>;
176174
deregister(scrollable: CdkScrollable): void;
177175
getAncestorScrollContainers(elementRef: ElementRef): CdkScrollable[];
@@ -188,9 +186,8 @@ export declare class ScrollingModule {
188186
}
189187

190188
export declare class ViewportRuler implements OnDestroy {
191-
protected _document?: Document;
192-
constructor(_platform: Platform, ngZone: NgZone,
193-
document?: any);
189+
protected _document: Document;
190+
constructor(_platform: Platform, ngZone: NgZone, document: any);
194191
change(throttleTime?: number): Observable<Event>;
195192
getViewportRect(): ClientRect;
196193
getViewportScrollPosition(): ViewportScrollPosition;

0 commit comments

Comments
 (0)