Skip to content

Commit dd04fe9

Browse files
committed
refactor(cdk/table): switch to input transforms
Switches inputs in cdk/table to use transforms instead of getters/setters.
1 parent ecd2cbd commit dd04fe9

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

src/cdk/table/cell.ts

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

9-
import {BooleanInput, coerceBooleanProperty} from '@angular/cdk/coercion';
109
import {
1110
ContentChild,
1211
Directive,
@@ -15,6 +14,7 @@ import {
1514
Input,
1615
Optional,
1716
TemplateRef,
17+
booleanAttribute,
1818
} from '@angular/core';
1919
import {CanStick, CanStickCtor, mixinHasStickyInput} from './can-stick';
2020
import {CDK_TABLE} from './tokens';
@@ -82,14 +82,15 @@ export class CdkColumnDef extends _CdkColumnDefBase implements CanStick {
8282
* that it mimics the `CanStick` mixin such that `_hasStickyChanged` is set to true if the value
8383
* has been changed.
8484
*/
85-
@Input('stickyEnd')
85+
@Input({transform: booleanAttribute})
8686
get stickyEnd(): boolean {
8787
return this._stickyEnd;
8888
}
89-
set stickyEnd(v: BooleanInput) {
90-
const prevValue = this._stickyEnd;
91-
this._stickyEnd = coerceBooleanProperty(v);
92-
this._hasStickyChanged = prevValue !== this._stickyEnd;
89+
set stickyEnd(value: boolean) {
90+
if (value !== this._stickyEnd) {
91+
this._stickyEnd = value;
92+
this._hasStickyChanged = true;
93+
}
9394
}
9495
_stickyEnd: boolean = false;
9596

src/cdk/table/table.ts

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

99
import {Direction, Directionality} from '@angular/cdk/bidi';
10-
import {BooleanInput, coerceBooleanProperty} from '@angular/cdk/coercion';
1110
import {
1211
CollectionViewer,
1312
DataSource,
@@ -52,6 +51,7 @@ import {
5251
ViewChild,
5352
ViewContainerRef,
5453
ViewEncapsulation,
54+
booleanAttribute,
5555
} from '@angular/core';
5656
import {
5757
BehaviorSubject,
@@ -432,12 +432,12 @@ export class CdkTable<T> implements AfterContentChecked, CollectionViewer, OnDes
432432
* dataobject will render the first row that evaluates its when predicate to true, in the order
433433
* defined in the table, or otherwise the default row which does not have a when predicate.
434434
*/
435-
@Input()
435+
@Input({transform: booleanAttribute})
436436
get multiTemplateDataRows(): boolean {
437437
return this._multiTemplateDataRows;
438438
}
439-
set multiTemplateDataRows(v: BooleanInput) {
440-
this._multiTemplateDataRows = coerceBooleanProperty(v);
439+
set multiTemplateDataRows(value: boolean) {
440+
this._multiTemplateDataRows = value;
441441

442442
// In Ivy if this value is set via a static attribute (e.g. <table multiTemplateDataRows>),
443443
// this setter will be invoked before the row outlet has been defined hence the null check.
@@ -452,12 +452,12 @@ export class CdkTable<T> implements AfterContentChecked, CollectionViewer, OnDes
452452
* Whether to use a fixed table layout. Enabling this option will enforce consistent column widths
453453
* and optimize rendering sticky styles for native tables. No-op for flex tables.
454454
*/
455-
@Input()
455+
@Input({transform: booleanAttribute})
456456
get fixedLayout(): boolean {
457457
return this._fixedLayout;
458458
}
459-
set fixedLayout(v: BooleanInput) {
460-
this._fixedLayout = coerceBooleanProperty(v);
459+
set fixedLayout(value: boolean) {
460+
this._fixedLayout = value;
461461

462462
// Toggling `fixedLayout` may change column widths. Sticky column styles should be recalculated.
463463
this._forceRecalculateCellWidths = true;

tools/public_api_guard/cdk/table.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import { AfterContentChecked } from '@angular/core';
88
import { BehaviorSubject } from 'rxjs';
9-
import { BooleanInput } from '@angular/cdk/coercion';
109
import { ChangeDetectorRef } from '@angular/core';
1110
import { CollectionViewer } from '@angular/cdk/collections';
1211
import { DataSource } from '@angular/cdk/collections';
@@ -149,9 +148,11 @@ export class CdkColumnDef extends _CdkColumnDefBase implements CanStick {
149148
set name(name: string);
150149
// (undocumented)
151150
protected _name: string;
151+
// (undocumented)
152+
static ngAcceptInputType_stickyEnd: unknown;
152153
protected _setNameInput(value: string): void;
153154
get stickyEnd(): boolean;
154-
set stickyEnd(v: BooleanInput);
155+
set stickyEnd(value: boolean);
155156
// (undocumented)
156157
_stickyEnd: boolean;
157158
// (undocumented)
@@ -314,7 +315,7 @@ export class CdkTable<T> implements AfterContentChecked, CollectionViewer, OnDes
314315
// (undocumented)
315316
protected readonly _elementRef: ElementRef;
316317
get fixedLayout(): boolean;
317-
set fixedLayout(v: BooleanInput);
318+
set fixedLayout(value: boolean);
318319
// (undocumented)
319320
_footerRowOutlet: FooterRowOutlet;
320321
_getRenderedRows(rowOutlet: RowOutlet): HTMLElement[];
@@ -323,11 +324,15 @@ export class CdkTable<T> implements AfterContentChecked, CollectionViewer, OnDes
323324
_headerRowOutlet: HeaderRowOutlet;
324325
protected _isNativeHtmlTable: boolean;
325326
get multiTemplateDataRows(): boolean;
326-
set multiTemplateDataRows(v: BooleanInput);
327+
set multiTemplateDataRows(value: boolean);
327328
// (undocumented)
328329
_multiTemplateDataRows: boolean;
329330
protected needsPositionStickyOnElement: boolean;
330331
// (undocumented)
332+
static ngAcceptInputType_fixedLayout: unknown;
333+
// (undocumented)
334+
static ngAcceptInputType_multiTemplateDataRows: unknown;
335+
// (undocumented)
331336
ngAfterContentChecked(): void;
332337
// (undocumented)
333338
ngOnDestroy(): void;

0 commit comments

Comments
 (0)