Skip to content

Commit 8bc7b01

Browse files
committed
fix: input coercion
1 parent e1d775d commit 8bc7b01

File tree

38 files changed

+507
-131
lines changed

38 files changed

+507
-131
lines changed

src/cdk/clipboard/copy-to-clipboard.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
Optional,
1818
OnDestroy,
1919
} from '@angular/core';
20+
import {coerceNumberProperty, NumberInput} from '@angular/cdk/coercion';
2021
import {Clipboard} from './clipboard';
2122
import {PendingCopy} from './pending-copy';
2223

@@ -54,7 +55,10 @@ export class CdkCopyToClipboard implements OnDestroy {
5455
* How many times to attempt to copy the text. This may be necessary for longer text, because
5556
* the browser needs time to fill an intermediate textarea element and copy the content.
5657
*/
57-
@Input('cdkCopyToClipboardAttempts') attempts: number = 1;
58+
@Input('cdkCopyToClipboardAttempts')
59+
get attempts(): number { return this._attempts; }
60+
set attempts(value: number) { this._attempts = coerceNumberProperty(value); }
61+
private _attempts = 1;
5862

5963
/**
6064
* Emits when some text is copied to the clipboard. The
@@ -115,4 +119,6 @@ export class CdkCopyToClipboard implements OnDestroy {
115119
this._pending.clear();
116120
this._destroyed = true;
117121
}
122+
123+
static ngAcceptInputType_attempts: NumberInput;
118124
}

src/cdk/drag-drop/directives/drop-list.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88

99
import {
1010
BooleanInput,
11+
NumberInput,
1112
coerceArray,
12-
coerceNumberProperty,
1313
coerceBooleanProperty,
14-
NumberInput,
14+
coerceNumberProperty,
1515
} from '@angular/cdk/coercion';
1616
import {
1717
ElementRef,
@@ -125,7 +125,13 @@ export class CdkDropList<T = any> implements OnDestroy {
125125

126126
/** Whether sorting within this drop list is disabled. */
127127
@Input('cdkDropListSortingDisabled')
128-
sortingDisabled: boolean;
128+
get sortingDisabled(): boolean {
129+
return this._sortingDisabled;
130+
}
131+
set sortingDisabled(value: boolean) {
132+
this._sortingDisabled = coerceBooleanProperty(value);
133+
}
134+
private _sortingDisabled: boolean;
129135

130136
/**
131137
* Function that is used to determine whether an item
@@ -140,11 +146,23 @@ export class CdkDropList<T = any> implements OnDestroy {
140146

141147
/** Whether to auto-scroll the view when the user moves their pointer close to the edges. */
142148
@Input('cdkDropListAutoScrollDisabled')
143-
autoScrollDisabled: boolean;
149+
get autoScrollDisabled(): boolean {
150+
return this._autoScrollDisabled;
151+
}
152+
set autoScrollDisabled(value: boolean) {
153+
this._autoScrollDisabled = coerceBooleanProperty(value);
154+
}
155+
private _autoScrollDisabled: boolean;
144156

145157
/** Number of pixels to scroll for each frame when auto-scrolling an element. */
146158
@Input('cdkDropListAutoScrollStep')
147-
autoScrollStep: number;
159+
get autoScrollStep(): number {
160+
return this._autoScrollStep;
161+
}
162+
set autoScrollStep(value: number) {
163+
this._autoScrollStep = coerceNumberProperty(value);
164+
}
165+
private _autoScrollStep: number;
148166

149167
/** Emits when the user drops an item inside the container. */
150168
@Output('cdkDropListDropped')

src/cdk/overlay/overlay-directives.ts

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

99
import {Direction, Directionality} from '@angular/cdk/bidi';
10-
import {BooleanInput, coerceBooleanProperty} from '@angular/cdk/coercion';
10+
import {
11+
BooleanInput,
12+
NumberInput,
13+
coerceBooleanProperty,
14+
coerceNumberProperty,
15+
} from '@angular/cdk/coercion';
1116
import {ESCAPE, hasModifierKey} from '@angular/cdk/keycodes';
1217
import {TemplatePortal} from '@angular/cdk/portal';
1318
import {
@@ -99,6 +104,9 @@ export class CdkOverlayOrigin {
99104
export class CdkConnectedOverlay implements OnDestroy, OnChanges {
100105
private _overlayRef: OverlayRef;
101106
private _templatePortal: TemplatePortal;
107+
private _viewportMargin = 0;
108+
private _open = false;
109+
private _disableClose = false;
102110
private _hasBackdrop = false;
103111
private _lockPosition = false;
104112
private _growAfterOpen = false;
@@ -129,7 +137,7 @@ export class CdkConnectedOverlay implements OnDestroy, OnChanges {
129137
@Input('cdkConnectedOverlayOffsetX')
130138
get offsetX(): number { return this._offsetX; }
131139
set offsetX(offsetX: number) {
132-
this._offsetX = offsetX;
140+
this._offsetX = coerceNumberProperty(offsetX);
133141

134142
if (this._position) {
135143
this._updatePositionStrategy(this._position);
@@ -140,7 +148,7 @@ export class CdkConnectedOverlay implements OnDestroy, OnChanges {
140148
@Input('cdkConnectedOverlayOffsetY')
141149
get offsetY() { return this._offsetY; }
142150
set offsetY(offsetY: number) {
143-
this._offsetY = offsetY;
151+
this._offsetY = coerceNumberProperty(offsetY);
144152

145153
if (this._position) {
146154
this._updatePositionStrategy(this._position);
@@ -166,16 +174,22 @@ export class CdkConnectedOverlay implements OnDestroy, OnChanges {
166174
@Input('cdkConnectedOverlayPanelClass') panelClass: string | string[];
167175

168176
/** Margin between the overlay and the viewport edges. */
169-
@Input('cdkConnectedOverlayViewportMargin') viewportMargin: number = 0;
177+
@Input('cdkConnectedOverlayViewportMargin')
178+
get viewportMargin(): number { return this._viewportMargin; }
179+
set viewportMargin(value: number) { this._viewportMargin = coerceNumberProperty(value); }
170180

171181
/** Strategy to be used when handling scroll events while the overlay is open. */
172182
@Input('cdkConnectedOverlayScrollStrategy') scrollStrategy: ScrollStrategy;
173183

174184
/** Whether the overlay is open. */
175-
@Input('cdkConnectedOverlayOpen') open: boolean = false;
185+
@Input('cdkConnectedOverlayOpen')
186+
get open() { return this._open; }
187+
set open(value: any) { this._open = coerceBooleanProperty(value); }
176188

177189
/** Whether the overlay can be closed by user interaction. */
178-
@Input('cdkConnectedOverlayDisableClose') disableClose: boolean = false;
190+
@Input('cdkConnectedOverlayDisableClose')
191+
get disableClose() { return this._disableClose; }
192+
set disableClose(value: any) { this._disableClose = coerceBooleanProperty(value); }
179193

180194
/** CSS selector which to set the transform origin. */
181195
@Input('cdkConnectedOverlayTransformOriginOn') transformOriginSelector: string;
@@ -418,6 +432,11 @@ export class CdkConnectedOverlay implements OnDestroy, OnChanges {
418432
this._positionSubscription.unsubscribe();
419433
}
420434

435+
static ngAcceptInputType_offsetX: NumberInput;
436+
static ngAcceptInputType_offsetY: NumberInput;
437+
static ngAcceptInputType_viewportMargin: NumberInput;
438+
static ngAcceptInputType_open: BooleanInput;
439+
static ngAcceptInputType_disableClose: BooleanInput;
421440
static ngAcceptInputType_hasBackdrop: BooleanInput;
422441
static ngAcceptInputType_lockPosition: BooleanInput;
423442
static ngAcceptInputType_flexibleDimensions: BooleanInput;

src/google-maps/google-map/google-map.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
EventEmitter,
2727
} from '@angular/core';
2828
import {isPlatformBrowser} from '@angular/common';
29+
import {NumberInput, coerceNumberProperty} from '@angular/cdk/coercion';
2930
import {Observable} from 'rxjs';
3031
import {MapEventManager} from '../map-event-manager';
3132

@@ -93,9 +94,7 @@ export class GoogleMap implements OnChanges, OnInit, OnDestroy {
9394
private _center: google.maps.LatLngLiteral|google.maps.LatLng;
9495

9596
@Input()
96-
set zoom(zoom: number) {
97-
this._zoom = zoom;
98-
}
97+
set zoom(zoom: number) { this._zoom = coerceNumberProperty(zoom); }
9998
private _zoom: number;
10099

101100
@Input()
@@ -505,6 +504,8 @@ export class GoogleMap implements OnChanges, OnInit, OnDestroy {
505504
'Please wait for the API to load before trying to interact with it.');
506505
}
507506
}
507+
508+
static ngAcceptInputType_zoom: NumberInput;
508509
}
509510

510511
const cssUnitsPattern = /([A-Za-z%]+)$/;

src/google-maps/map-circle/map-circle.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
/// <reference types="googlemaps" />
1111

1212
import {Directive, Input, NgZone, OnDestroy, OnInit, Output} from '@angular/core';
13+
import {NumberInput, coerceNumberProperty} from '@angular/cdk/coercion';
1314
import {BehaviorSubject, combineLatest, Observable, Subject} from 'rxjs';
1415
import {map, take, takeUntil} from 'rxjs/operators';
1516

@@ -52,7 +53,7 @@ export class MapCircle implements OnInit, OnDestroy {
5253

5354
@Input()
5455
set radius(radius: number) {
55-
this._radius.next(radius);
56+
this._radius.next(coerceNumberProperty(radius));
5657
}
5758

5859
/**
@@ -282,4 +283,6 @@ export class MapCircle implements OnInit, OnDestroy {
282283
}
283284
}
284285
}
286+
287+
static ngAcceptInputType_radius: NumberInput;
285288
}

src/google-maps/map-ground-overlay/map-ground-overlay.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
/// <reference types="googlemaps" />
1111

1212
import {Directive, Input, NgZone, OnDestroy, OnInit, Output} from '@angular/core';
13+
import {
14+
BooleanInput,
15+
NumberInput,
16+
coerceBooleanProperty,
17+
coerceNumberProperty
18+
} from '@angular/cdk/coercion';
1319
import {BehaviorSubject, Observable, Subject} from 'rxjs';
1420
import {takeUntil} from 'rxjs/operators';
1521

@@ -27,6 +33,7 @@ import {MapEventManager} from '../map-event-manager';
2733
})
2834
export class MapGroundOverlay implements OnInit, OnDestroy {
2935
private _eventManager = new MapEventManager(this._ngZone);
36+
private _clickable = false;
3037

3138
private readonly _opacity = new BehaviorSubject<number>(1);
3239
private readonly _url = new BehaviorSubject<string>('');
@@ -58,12 +65,14 @@ export class MapGroundOverlay implements OnInit, OnDestroy {
5865
}
5966

6067
/** Whether the overlay is clickable */
61-
@Input() clickable: boolean = false;
68+
@Input()
69+
get clickable() { return this._clickable; }
70+
set clickable(value: any) { this._clickable = coerceBooleanProperty(value); }
6271

6372
/** Opacity of the overlay. */
6473
@Input()
6574
set opacity(opacity: number) {
66-
this._opacity.next(opacity);
75+
this._opacity.next(coerceNumberProperty(opacity));
6776
}
6877

6978
/**
@@ -189,4 +198,7 @@ export class MapGroundOverlay implements OnInit, OnDestroy {
189198
}
190199
}
191200
}
201+
202+
static ngAcceptInputType_clickable: BooleanInput;
203+
static ngAcceptInputType_opacity: NumberInput;
192204
}

src/google-maps/map-marker-clusterer/map-marker-clusterer.ts

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ import {
2525
SimpleChanges,
2626
ViewEncapsulation
2727
} from '@angular/core';
28+
import {
29+
BooleanInput,
30+
NumberInput,
31+
coerceArray,
32+
coerceBooleanProperty,
33+
coerceNumberProperty
34+
} from '@angular/cdk/coercion';
2835
import {Observable, Subject} from 'rxjs';
2936
import {takeUntil} from 'rxjs/operators';
3037

@@ -60,15 +67,18 @@ export class MapMarkerClusterer implements OnInit, AfterContentInit, OnChanges,
6067

6168
@Input()
6269
set averageCenter(averageCenter: boolean) {
63-
this._averageCenter = averageCenter;
70+
this._averageCenter = coerceBooleanProperty(averageCenter);
6471
}
6572
private _averageCenter: boolean;
6673

67-
@Input() batchSize?: number;
74+
@Input()
75+
get batchSize(): number | undefined { return this._batchSize; }
76+
set batchSize(value: any) { this._batchSize = coerceNumberProperty(value); }
77+
private _batchSize?: number;
6878

6979
@Input()
7080
set batchSizeIE(batchSizeIE: number) {
71-
this._batchSizeIE = batchSizeIE;
81+
this._batchSizeIE = coerceNumberProperty(batchSizeIE);
7282
}
7383
private _batchSizeIE: number;
7484

@@ -86,19 +96,19 @@ export class MapMarkerClusterer implements OnInit, AfterContentInit, OnChanges,
8696

8797
@Input()
8898
set enableRetinaIcons(enableRetinaIcons: boolean) {
89-
this._enableRetinaIcons = enableRetinaIcons;
99+
this._enableRetinaIcons = coerceBooleanProperty(enableRetinaIcons);
90100
}
91101
private _enableRetinaIcons: boolean;
92102

93103
@Input()
94104
set gridSize(gridSize: number) {
95-
this._gridSize = gridSize;
105+
this._gridSize = coerceNumberProperty(gridSize);
96106
}
97107
private _gridSize: number;
98108

99109
@Input()
100110
set ignoreHidden(ignoreHidden: boolean) {
101-
this._ignoreHidden = ignoreHidden;
111+
this._ignoreHidden = coerceBooleanProperty(ignoreHidden);
102112
}
103113
private _ignoreHidden: boolean;
104114

@@ -115,20 +125,20 @@ export class MapMarkerClusterer implements OnInit, AfterContentInit, OnChanges,
115125
private _imagePath: string;
116126

117127
@Input()
118-
set imageSizes(imageSizes: number[]) {
119-
this._imageSizes = imageSizes;
128+
set imageSizes(imageSizes: number | number[]) {
129+
this._imageSizes = coerceArray(imageSizes);
120130
}
121131
private _imageSizes: number[];
122132

123133
@Input()
124134
set maxZoom(maxZoom: number) {
125-
this._maxZoom = maxZoom;
135+
this._maxZoom = coerceNumberProperty(maxZoom);
126136
}
127137
private _maxZoom: number;
128138

129139
@Input()
130140
set minimumClusterSize(minimumClusterSize: number) {
131-
this._minimumClusterSize = minimumClusterSize;
141+
this._minimumClusterSize = coerceNumberProperty(minimumClusterSize);
132142
}
133143
private _minimumClusterSize: number;
134144

@@ -146,13 +156,13 @@ export class MapMarkerClusterer implements OnInit, AfterContentInit, OnChanges,
146156

147157
@Input()
148158
set zIndex(zIndex: number) {
149-
this._zIndex = zIndex;
159+
this._zIndex = coerceNumberProperty(zIndex);
150160
}
151161
private _zIndex: number;
152162

153163
@Input()
154164
set zoomOnClick(zoomOnClick: boolean) {
155-
this._zoomOnClick = zoomOnClick;
165+
this._zoomOnClick = coerceBooleanProperty(zoomOnClick);
156166
}
157167
private _zoomOnClick: boolean;
158168

@@ -480,4 +490,15 @@ export class MapMarkerClusterer implements OnInit, AfterContentInit, OnChanges,
480490
}
481491
}
482492
}
493+
494+
static ngAcceptInputType_averageCenter: BooleanInput;
495+
static ngAcceptInputType_batchSize: NumberInput;
496+
static ngAcceptInputType_batchSizeIE: NumberInput;
497+
static ngAcceptInputType_enableRetinaIcons: BooleanInput;
498+
static ngAcceptInputType_gridSize: NumberInput;
499+
static ngAcceptInputType_ignoreHidden: BooleanInput;
500+
static ngAcceptInputType_maxZoom: NumberInput;
501+
static ngAcceptInputType_minimumClusterSize: NumberInput;
502+
static ngAcceptInputType_zIndex: NumberInput;
503+
static ngAcceptInputType_zoomOnClick: BooleanInput;
483504
}

0 commit comments

Comments
 (0)