@@ -26,6 +26,18 @@ import {coerceNumberProperty} from '@angular/cdk/coercion';
26
26
/** Possible mode for a progress spinner. */
27
27
export type ProgressSpinnerMode = 'determinate' | 'indeterminate' ;
28
28
29
+ /**
30
+ * Base reference size of the spinner.
31
+ * @docs -private
32
+ */
33
+ const BASE_SIZE = 100 ;
34
+
35
+ /**
36
+ * Base reference stroke width of the spinner.
37
+ * @docs -private
38
+ */
39
+ const BASE_STROKE_WIDTH = 10 ;
40
+
29
41
// Boilerplate for applying mixins to MatProgressSpinner.
30
42
/** @docs -private */
31
43
export class MatProgressSpinnerBase {
@@ -84,17 +96,15 @@ const INDETERMINATE_ANIMATION_TEMPLATE = `
84
96
export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements CanColor ,
85
97
OnChanges {
86
98
87
- private _value : number = 0 ;
88
- private readonly _baseSize = 100 ;
89
- private readonly _baseStrokeWidth = 10 ;
90
- private _fallbackAnimation = false ;
99
+ private _value = 0 ;
91
100
private _strokeWidth : number ;
101
+ private _fallbackAnimation = false ;
92
102
93
103
/** The width and height of the host element. Will grow with stroke width. **/
94
- _elementSize = this . _baseSize ;
104
+ _elementSize = BASE_SIZE ;
95
105
96
106
/** Tracks diameters of existing instances to de-dupe generated styles (default d = 100) */
97
- private static diameters = new Set < number > ( [ 100 ] ) ;
107
+ private static diameters = new Set < number > ( [ BASE_SIZE ] ) ;
98
108
99
109
/**
100
110
* Used for storing all of the generated keyframe animations.
@@ -107,11 +117,14 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements
107
117
get diameter ( ) : number {
108
118
return this . _diameter ;
109
119
}
110
-
111
120
set diameter ( size : number ) {
112
- this . _setDiameterAndInitStyles ( size ) ;
121
+ this . _diameter = coerceNumberProperty ( size ) ;
122
+
123
+ if ( ! this . _fallbackAnimation && ! MatProgressSpinner . diameters . has ( this . _diameter ) ) {
124
+ this . _attachStyleNode ( ) ;
125
+ }
113
126
}
114
- _diameter = this . _baseSize ;
127
+ private _diameter = BASE_SIZE ;
115
128
116
129
/** Stroke width of the progress spinner. */
117
130
@Input ( )
@@ -134,7 +147,7 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements
134
147
}
135
148
set value ( newValue : number ) {
136
149
if ( newValue != null && this . mode === 'determinate' ) {
137
- this . _value = Math . max ( 0 , Math . min ( 100 , newValue ) ) ;
150
+ this . _value = Math . max ( 0 , Math . min ( 100 , coerceNumberProperty ( newValue ) ) ) ;
138
151
}
139
152
}
140
153
@@ -154,14 +167,13 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements
154
167
155
168
ngOnChanges ( changes : SimpleChanges ) {
156
169
if ( changes . strokeWidth || changes . diameter ) {
157
- this . _elementSize =
158
- this . _diameter + Math . max ( this . strokeWidth - this . _baseStrokeWidth , 0 ) ;
170
+ this . _elementSize = this . _diameter + Math . max ( this . strokeWidth - BASE_STROKE_WIDTH , 0 ) ;
159
171
}
160
172
}
161
173
162
174
/** The radius of the spinner, adjusted for stroke width. */
163
175
get _circleRadius ( ) {
164
- return ( this . diameter - this . _baseStrokeWidth ) / 2 ;
176
+ return ( this . diameter - BASE_STROKE_WIDTH ) / 2 ;
165
177
}
166
178
167
179
/** The view box of the spinner's svg element. */
@@ -194,14 +206,6 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements
194
206
return this . strokeWidth / this . _elementSize * 100 ;
195
207
}
196
208
197
- /** Sets the diameter and adds diameter-specific styles if necessary. */
198
- private _setDiameterAndInitStyles ( size : number ) : void {
199
- this . _diameter = size ;
200
- if ( ! MatProgressSpinner . diameters . has ( this . diameter ) && ! this . _fallbackAnimation ) {
201
- this . _attachStyleNode ( ) ;
202
- }
203
- }
204
-
205
209
/** Dynamically generates a style tag containing the correct animation for this diameter. */
206
210
private _attachStyleNode ( ) : void {
207
211
let styleTag = MatProgressSpinner . styleTag ;
0 commit comments