7
7
*/
8
8
9
9
import {
10
- AfterViewInit ,
11
10
ChangeDetectionStrategy ,
12
11
Component ,
13
12
ElementRef ,
14
13
Inject ,
15
14
Input ,
16
- OnDestroy ,
17
15
Optional ,
18
16
ViewChild ,
19
17
ViewEncapsulation ,
20
18
} from '@angular/core' ;
21
- import {
22
- MDCCircularProgressAdapter ,
23
- MDCCircularProgressFoundation ,
24
- } from '@material/circular-progress' ;
25
19
import { CanColor , mixinColor } from '@angular/material-experimental/mdc-core' ;
26
20
import { ANIMATION_MODULE_TYPE } from '@angular/platform-browser/animations' ;
27
21
import {
@@ -61,6 +55,7 @@ const BASE_STROKE_WIDTH = 10;
61
55
// Note: there is a known issue with JAWS that does not read progressbar aria labels on FireFox
62
56
'tabindex' : '-1' ,
63
57
'[class._mat-animation-noopable]' : `_noopAnimations` ,
58
+ '[class.mdc-circular-progress--indeterminate]' : 'mode === "indeterminate"' ,
64
59
'[style.width.px]' : 'diameter' ,
65
60
'[style.height.px]' : 'diameter' ,
66
61
'[attr.aria-valuemin]' : '0' ,
@@ -74,41 +69,13 @@ const BASE_STROKE_WIDTH = 10;
74
69
changeDetection : ChangeDetectionStrategy . OnPush ,
75
70
encapsulation : ViewEncapsulation . None ,
76
71
} )
77
- export class MatProgressSpinner
78
- extends _MatProgressSpinnerBase
79
- implements AfterViewInit , OnDestroy , CanColor
80
- {
72
+ export class MatProgressSpinner extends _MatProgressSpinnerBase implements CanColor {
81
73
/** Whether the _mat-animation-noopable class should be applied, disabling animations. */
82
74
_noopAnimations : boolean ;
83
75
84
- /** Implements all of the logic of the MDC circular progress. */
85
- _foundation : MDCCircularProgressFoundation ;
86
-
87
76
/** The element of the determinate spinner. */
88
77
@ViewChild ( 'determinateSpinner' ) _determinateCircle : ElementRef < HTMLElement > ;
89
78
90
- /** Adapter used by MDC to interact with the DOM. */
91
- // TODO: switch to class when MDC removes object spread in foundation
92
- // https://github.com/material-components/material-components-web/pull/6256
93
- private _adapter : MDCCircularProgressAdapter = {
94
- addClass : ( className : string ) => this . _elementRef . nativeElement . classList . add ( className ) ,
95
- hasClass : ( className : string ) => this . _elementRef . nativeElement . classList . contains ( className ) ,
96
- removeClass : ( className : string ) => this . _elementRef . nativeElement . classList . remove ( className ) ,
97
- removeAttribute : ( name : string ) => this . _elementRef . nativeElement . removeAttribute ( name ) ,
98
- setAttribute : ( name , value ) => {
99
- if ( name !== 'aria-valuenow' ) {
100
- // MDC deals with values between 0 and 1 but Angular Material deals with values between
101
- // 0 and 100 so the aria-valuenow should be set through the attr binding in the host
102
- // instead of by the MDC adapter
103
- this . _elementRef . nativeElement . setAttribute ( name , value ) ;
104
- }
105
- } ,
106
- getDeterminateCircleAttribute : ( attributeName : string ) =>
107
- this . _determinateCircle . nativeElement . getAttribute ( attributeName ) ,
108
- setDeterminateCircleAttribute : ( attributeName : string , value : string ) =>
109
- this . _determinateCircle . nativeElement . setAttribute ( attributeName , value ) ,
110
- } ;
111
-
112
79
constructor (
113
80
elementRef : ElementRef < HTMLElement > ,
114
81
@Optional ( ) @Inject ( ANIMATION_MODULE_TYPE ) animationMode : string ,
@@ -134,65 +101,47 @@ export class MatProgressSpinner
134
101
}
135
102
}
136
103
137
- private _mode : ProgressSpinnerMode =
138
- this . _elementRef . nativeElement . nodeName . toLowerCase ( ) === 'mat-spinner'
139
- ? 'indeterminate'
140
- : 'determinate' ;
141
-
142
104
/**
143
105
* Mode of the progress bar.
144
106
*
145
107
* Input must be one of these values: determinate, indeterminate, buffer, query, defaults to
146
108
* 'determinate'.
147
109
* Mirrored to mode attribute.
148
110
*/
149
- @Input ( )
150
- get mode ( ) : ProgressSpinnerMode {
151
- return this . _mode ;
152
- }
153
-
154
- set mode ( value : ProgressSpinnerMode ) {
155
- this . _mode = value ;
156
- this . _syncFoundation ( ) ;
157
- }
158
-
159
- private _value = 0 ;
111
+ @Input ( ) mode : ProgressSpinnerMode =
112
+ this . _elementRef . nativeElement . nodeName . toLowerCase ( ) === 'mat-spinner'
113
+ ? 'indeterminate'
114
+ : 'determinate' ;
160
115
161
116
/** Value of the progress bar. Defaults to zero. Mirrored to aria-valuenow. */
162
117
@Input ( )
163
118
get value ( ) : number {
164
119
return this . mode === 'determinate' ? this . _value : 0 ;
165
120
}
166
-
167
121
set value ( v : NumberInput ) {
168
122
this . _value = Math . max ( 0 , Math . min ( 100 , coerceNumberProperty ( v ) ) ) ;
169
- this . _syncFoundation ( ) ;
170
123
}
171
-
172
- private _diameter = BASE_SIZE ;
124
+ private _value = 0 ;
173
125
174
126
/** The diameter of the progress spinner (will set width and height of svg). */
175
127
@Input ( )
176
128
get diameter ( ) : number {
177
129
return this . _diameter ;
178
130
}
179
-
180
131
set diameter ( size : NumberInput ) {
181
132
this . _diameter = coerceNumberProperty ( size ) ;
182
- this . _syncFoundation ( ) ;
183
133
}
184
-
185
- private _strokeWidth : number ;
134
+ private _diameter = BASE_SIZE ;
186
135
187
136
/** Stroke width of the progress spinner. */
188
137
@Input ( )
189
138
get strokeWidth ( ) : number {
190
139
return this . _strokeWidth ?? this . diameter / 10 ;
191
140
}
192
-
193
141
set strokeWidth ( value : NumberInput ) {
194
142
this . _strokeWidth = coerceNumberProperty ( value ) ;
195
143
}
144
+ private _strokeWidth : number ;
196
145
197
146
/** The radius of the spinner, adjusted for stroke width. */
198
147
_circleRadius ( ) : number {
@@ -222,29 +171,6 @@ export class MatProgressSpinner
222
171
_circleStrokeWidth ( ) {
223
172
return ( this . strokeWidth / this . diameter ) * 100 ;
224
173
}
225
-
226
- ngAfterViewInit ( ) {
227
- this . _foundation = new MDCCircularProgressFoundation ( this . _adapter ) ;
228
- this . _foundation . init ( ) ;
229
- this . _syncFoundation ( ) ;
230
- }
231
-
232
- ngOnDestroy ( ) {
233
- if ( this . _foundation ) {
234
- this . _foundation . destroy ( ) ;
235
- }
236
- }
237
-
238
- /** Syncs the state of the progress spinner with the MDC foundation. */
239
- private _syncFoundation ( ) {
240
- const foundation = this . _foundation ;
241
-
242
- if ( foundation ) {
243
- const mode = this . mode ;
244
- foundation . setProgress ( this . value / 100 ) ;
245
- foundation . setDeterminate ( mode === 'determinate' ) ;
246
- }
247
- }
248
174
}
249
175
250
176
/**
0 commit comments