Skip to content

Commit 908df0e

Browse files
committed
fix(progress-spinner): unable to change mode on spinner directive
Currently we have the `mat-spinner` directive which is a shortcut to a `mat-progress-spinner` with `mode="indeterminate"`. Since the spinner inherits all of the inputs from the progress spinner, there's nothing stoping people from changing the mode back to `determinate`, however the element will look half-broken because the host bindings assume that the mode won't change. These changes update the host bindings to allow switching between modes. Fixes #14511.
1 parent ecaec18 commit 908df0e

File tree

2 files changed

+24
-35
lines changed

2 files changed

+24
-35
lines changed

src/lib/progress-spinner/progress-spinner.spec.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
} from './index';
99

1010

11-
describe('MatProgressSpinner', () => {
11+
fdescribe('MatProgressSpinner', () => {
1212

1313
beforeEach(async(() => {
1414
TestBed.configureTestingModule({
@@ -22,6 +22,7 @@ describe('MatProgressSpinner', () => {
2222
ProgressSpinnerCustomDiameter,
2323
SpinnerWithColor,
2424
ProgressSpinnerWithStringValues,
25+
SpinnerWithMode,
2526
],
2627
}).compileComponents();
2728
}));
@@ -296,6 +297,14 @@ describe('MatProgressSpinner', () => {
296297
expect(progressElement.componentInstance.strokeWidth).toBe(7);
297298
});
298299

300+
it('should be able to change the mode on a mat-spinner', () => {
301+
const fixture = TestBed.createComponent(SpinnerWithMode);
302+
fixture.detectChanges();
303+
304+
const progressElement = fixture.debugElement.query(By.css('mat-spinner')).nativeElement;
305+
expect(progressElement.getAttribute('mode')).toBe('determinate');
306+
});
307+
299308
});
300309

301310

@@ -335,3 +344,7 @@ class ProgressSpinnerWithColor { color: string = 'primary'; }
335344
`
336345
})
337346
class ProgressSpinnerWithStringValues { }
347+
348+
@Component({template: '<mat-spinner mode="determinate"></mat-spinner>'})
349+
class SpinnerWithMode { }
350+

src/lib/progress-spinner/progress-spinner.ts

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ const INDETERMINATE_ANIMATION_TEMPLATE = `
104104
*/
105105
@Component({
106106
moduleId: module.id,
107-
selector: 'mat-progress-spinner',
107+
selector: 'mat-progress-spinner, mat-spinner',
108108
exportAs: 'matProgressSpinner',
109109
host: {
110110
'role': 'progressbar',
@@ -186,6 +186,10 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements
186186
super(_elementRef);
187187
this._fallbackAnimation = platform.EDGE || platform.TRIDENT;
188188

189+
if (_elementRef.nativeElement.nodeName.toLowerCase() === 'mat-spinner') {
190+
this.mode = 'indeterminate';
191+
}
192+
189193
if (defaults) {
190194
if (defaults.diameter) {
191195
this.diameter = defaults.diameter;
@@ -266,38 +270,10 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements
266270
}
267271
}
268272

269-
270273
/**
271-
* `<mat-spinner>` component.
272-
*
273-
* This is a component definition to be used as a convenience reference to create an
274-
* indeterminate `<mat-progress-spinner>` instance.
274+
* @deprecated Import `MatProgressSpinner` instead. Note that the
275+
* `mat-spinner` selector isn't deprecated.
276+
* @breaking-change 8.0.0
275277
*/
276-
@Component({
277-
moduleId: module.id,
278-
selector: 'mat-spinner',
279-
host: {
280-
'role': 'progressbar',
281-
'mode': 'indeterminate',
282-
'class': 'mat-spinner mat-progress-spinner',
283-
'[class._mat-animation-noopable]': `_noopAnimations`,
284-
'[style.width.px]': 'diameter',
285-
'[style.height.px]': 'diameter',
286-
},
287-
inputs: ['color'],
288-
templateUrl: 'progress-spinner.html',
289-
styleUrls: ['progress-spinner.css'],
290-
changeDetection: ChangeDetectionStrategy.OnPush,
291-
encapsulation: ViewEncapsulation.None,
292-
})
293-
export class MatSpinner extends MatProgressSpinner {
294-
constructor(elementRef: ElementRef, platform: Platform,
295-
@Optional() @Inject(DOCUMENT) document: any,
296-
// @breaking-change 8.0.0 animationMode and defaults parameters to be made required.
297-
@Optional() @Inject(ANIMATION_MODULE_TYPE) animationMode?: string,
298-
@Inject(MAT_PROGRESS_SPINNER_DEFAULT_OPTIONS)
299-
defaults?: MatProgressSpinnerDefaultOptions) {
300-
super(elementRef, platform, document, animationMode, defaults);
301-
this.mode = 'indeterminate';
302-
}
303-
}
278+
// tslint:disable-next-line:variable-name
279+
export const MatSpinner = MatProgressSpinner;

0 commit comments

Comments
 (0)