Skip to content

Commit 4c6a169

Browse files
committed
fix(cdk/table): revert breaking constructor changes
In #19964 and #19750 some breaking constructor changes were made which eventually got released as a part of a patch branch which doesn't follow our breaking changes policy. These changes make the new constructor parameters optional and add fallbacks to the old behavior. Fixes #20422.
1 parent f33210c commit 4c6a169

File tree

3 files changed

+41
-16
lines changed

3 files changed

+41
-16
lines changed

src/cdk/table/sticky-styler.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ export class StickyStyler {
4242
constructor(private _isNativeHtmlTable: boolean,
4343
private _stickCellCss: string,
4444
public direction: Direction,
45-
private _coalescedStyleScheduler: _CoalescedStyleScheduler,
45+
/**
46+
* @deprecated `_coalescedStyleScheduler` parameter to become required.
47+
* @breaking-change 11.0.0
48+
*/
49+
private _coalescedStyleScheduler?: _CoalescedStyleScheduler,
4650
private _isBrowser = true,
4751
private readonly _needsPositionStickyOnElement = true) { }
4852

@@ -68,7 +72,7 @@ export class StickyStyler {
6872
}
6973

7074
// Coalesce with sticky row/column updates (and potentially other changes like column resize).
71-
this._coalescedStyleScheduler.schedule(() => {
75+
this._scheduleStyleChanges(() => {
7276
for (const element of elementsToClear) {
7377
this._removeStickyStyle(element, stickyDirections);
7478
}
@@ -99,7 +103,7 @@ export class StickyStyler {
99103
const endPositions = this._getStickyEndColumnPositions(cellWidths, stickyEndStates);
100104

101105
// Coalesce with sticky row updates (and potentially other changes like column resize).
102-
this._coalescedStyleScheduler.schedule(() => {
106+
this._scheduleStyleChanges(() => {
103107
const isRtl = this.direction === 'rtl';
104108
const start = isRtl ? 'right' : 'left';
105109
const end = isRtl ? 'left' : 'right';
@@ -163,7 +167,7 @@ export class StickyStyler {
163167

164168
// Coalesce with other sticky row updates (top/bottom), sticky columns updates
165169
// (and potentially other changes like column resize).
166-
this._coalescedStyleScheduler.schedule(() => {
170+
this._scheduleStyleChanges(() => {
167171
for (let rowIndex = 0; rowIndex < rows.length; rowIndex++) {
168172
if (!states[rowIndex]) {
169173
continue;
@@ -191,7 +195,7 @@ export class StickyStyler {
191195
const tfoot = tableElement.querySelector('tfoot')!;
192196

193197
// Coalesce with other sticky updates (and potentially other changes like column resize).
194-
this._coalescedStyleScheduler.schedule(() => {
198+
this._scheduleStyleChanges(() => {
195199
if (stickyStates.some(state => !state)) {
196200
this._removeStickyStyle(tfoot, ['bottom']);
197201
} else {
@@ -323,4 +327,17 @@ export class StickyStyler {
323327

324328
return positions;
325329
}
330+
331+
/**
332+
* Schedules styles to be applied when the style scheduler deems appropriate.
333+
* @breaking-change 11.0.0 This method can be removed in favor of calling
334+
* `CoalescedStyleScheduler.schedule` directly once the scheduler is a required parameter.
335+
*/
336+
private _scheduleStyleChanges(changes: () => void) {
337+
if (this._coalescedStyleScheduler) {
338+
this._coalescedStyleScheduler.schedule(changes);
339+
} else {
340+
changes();
341+
}
342+
}
326343
}

src/cdk/table/table.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -443,14 +443,17 @@ export class CdkTable<T> implements AfterContentChecked, CollectionViewer, OnDes
443443
constructor(
444444
protected readonly _differs: IterableDiffers,
445445
protected readonly _changeDetectorRef: ChangeDetectorRef,
446-
protected readonly _coalescedStyleScheduler: _CoalescedStyleScheduler,
447446
protected readonly _elementRef: ElementRef, @Attribute('role') role: string,
448447
@Optional() protected readonly _dir: Directionality, @Inject(DOCUMENT) _document: any,
449448
private _platform: Platform,
450-
// Optional for backwards compatibility, but a view repeater strategy will always
451-
// be provided.
449+
450+
/**
451+
* @deprecated `_coalescedStyleScheduler` and `_viewRepeater` parameters to become required.
452+
* @breaking-change 11.0.0
453+
*/
452454
@Optional() @Inject(_VIEW_REPEATER_STRATEGY)
453-
protected readonly _viewRepeater: _ViewRepeater<T, RenderRow<T>, RowContext<T>>) {
455+
protected readonly _viewRepeater?: _ViewRepeater<T, RenderRow<T>, RowContext<T>>,
456+
@Optional() protected readonly _coalescedStyleScheduler?: _CoalescedStyleScheduler) {
454457
if (!role) {
455458
this._elementRef.nativeElement.setAttribute('role', 'grid');
456459
}
@@ -549,11 +552,14 @@ export class CdkTable<T> implements AfterContentChecked, CollectionViewer, OnDes
549552
return;
550553
}
551554
const viewContainer = this._rowOutlet.viewContainer;
552-
this._viewRepeater.applyChanges(
555+
556+
// @breaking-change 11.0.0 Remove null check for `_viewRepeater`
557+
// once it's a required parameter in the constructor.
558+
this._viewRepeater?.applyChanges(
553559
changes,
554560
viewContainer,
555561
(record: IterableChangeRecord<RenderRow<T>>,
556-
adjustedPreviousIndex: number|null,
562+
_adjustedPreviousIndex: number|null,
557563
currentIndex: number|null) => this._getEmbeddedViewArgs(record.item, currentIndex!),
558564
(record) => record.item.data,
559565
(change: _ViewRepeaterItemChange<RenderRow<T>, RowContext<T>>) => {

tools/public_api_guard/cdk/table.d.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ export declare class CdkRowDef<T> extends BaseRowDef {
186186

187187
export declare class CdkTable<T> implements AfterContentChecked, CollectionViewer, OnDestroy, OnInit {
188188
protected readonly _changeDetectorRef: ChangeDetectorRef;
189-
protected readonly _coalescedStyleScheduler: _CoalescedStyleScheduler;
189+
protected readonly _coalescedStyleScheduler?: _CoalescedStyleScheduler | undefined;
190190
_contentColumnDefs: QueryList<CdkColumnDef>;
191191
_contentFooterRowDefs: QueryList<CdkFooterRowDef>;
192192
_contentHeaderRowDefs: QueryList<CdkHeaderRowDef>;
@@ -201,7 +201,7 @@ export declare class CdkTable<T> implements AfterContentChecked, CollectionViewe
201201
_noDataRow: CdkNoDataRow;
202202
_noDataRowOutlet: NoDataRowOutlet;
203203
_rowOutlet: DataRowOutlet;
204-
protected readonly _viewRepeater: _ViewRepeater<T, RenderRow<T>, RowContext<T>>;
204+
protected readonly _viewRepeater?: _ViewRepeater<T, RenderRow<T>, RowContext<T>> | undefined;
205205
get dataSource(): CdkTableDataSourceInput<T>;
206206
set dataSource(dataSource: CdkTableDataSourceInput<T>);
207207
get multiTemplateDataRows(): boolean;
@@ -214,7 +214,8 @@ export declare class CdkTable<T> implements AfterContentChecked, CollectionViewe
214214
start: number;
215215
end: number;
216216
}>;
217-
constructor(_differs: IterableDiffers, _changeDetectorRef: ChangeDetectorRef, _coalescedStyleScheduler: _CoalescedStyleScheduler, _elementRef: ElementRef, role: string, _dir: Directionality, _document: any, _platform: Platform, _viewRepeater: _ViewRepeater<T, RenderRow<T>, RowContext<T>>);
217+
constructor(_differs: IterableDiffers, _changeDetectorRef: ChangeDetectorRef, _elementRef: ElementRef, role: string, _dir: Directionality, _document: any, _platform: Platform,
218+
_viewRepeater?: _ViewRepeater<T, RenderRow<T>, RowContext<T>> | undefined, _coalescedStyleScheduler?: _CoalescedStyleScheduler | undefined);
218219
_getRenderedRows(rowOutlet: RowOutlet): HTMLElement[];
219220
_getRowDefs(data: T, dataIndex: number): CdkRowDef<T>[];
220221
addColumnDef(columnDef: CdkColumnDef): void;
@@ -234,7 +235,7 @@ export declare class CdkTable<T> implements AfterContentChecked, CollectionViewe
234235
updateStickyHeaderRowStyles(): void;
235236
static ngAcceptInputType_multiTemplateDataRows: BooleanInput;
236237
static ɵcmp: i0.ɵɵComponentDefWithMeta<CdkTable<any>, "cdk-table, table[cdk-table]", ["cdkTable"], { "trackBy": "trackBy"; "dataSource": "dataSource"; "multiTemplateDataRows": "multiTemplateDataRows"; }, {}, ["_noDataRow", "_contentColumnDefs", "_contentRowDefs", "_contentHeaderRowDefs", "_contentFooterRowDefs"], ["caption", "colgroup, col"]>;
237-
static ɵfac: i0.ɵɵFactoryDef<CdkTable<any>, [null, null, null, null, { attribute: "role"; }, { optional: true; }, null, null, { optional: true; }]>;
238+
static ɵfac: i0.ɵɵFactoryDef<CdkTable<any>, [null, null, null, { attribute: "role"; }, { optional: true; }, null, null, { optional: true; }, { optional: true; }]>;
238239
}
239240

240241
export declare class CdkTableModule {
@@ -319,7 +320,8 @@ export declare type StickyDirection = 'top' | 'bottom' | 'left' | 'right';
319320

320321
export declare class StickyStyler {
321322
direction: Direction;
322-
constructor(_isNativeHtmlTable: boolean, _stickCellCss: string, direction: Direction, _coalescedStyleScheduler: _CoalescedStyleScheduler, _isBrowser?: boolean, _needsPositionStickyOnElement?: boolean);
323+
constructor(_isNativeHtmlTable: boolean, _stickCellCss: string, direction: Direction,
324+
_coalescedStyleScheduler?: _CoalescedStyleScheduler | undefined, _isBrowser?: boolean, _needsPositionStickyOnElement?: boolean);
323325
_addStickyStyle(element: HTMLElement, dir: StickyDirection, dirValue: number): void;
324326
_getCalculatedZIndex(element: HTMLElement): string;
325327
_getCellWidths(row: HTMLElement): number[];

0 commit comments

Comments
 (0)