Skip to content

Commit c7fbb43

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 e5efd0a commit c7fbb43

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,11 +278,14 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements
278278
selector: 'mat-spinner',
279279
host: {
280280
'role': 'progressbar',
281-
'mode': 'indeterminate',
282281
'class': 'mat-spinner mat-progress-spinner',
283282
'[class._mat-animation-noopable]': `_noopAnimations`,
284283
'[style.width.px]': 'diameter',
285284
'[style.height.px]': 'diameter',
285+
'[attr.aria-valuemin]': 'mode === "determinate" ? 0 : null',
286+
'[attr.aria-valuemax]': 'mode === "determinate" ? 100 : null',
287+
'[attr.aria-valuenow]': 'value',
288+
'[attr.mode]': 'mode',
286289
},
287290
inputs: ['color'],
288291
templateUrl: 'progress-spinner.html',

0 commit comments

Comments
 (0)