Skip to content

Commit a5944da

Browse files
josephperrottjelbourn
authored andcommitted
fix(spinner): omit min/max/value for indeterminate and correctly set mode (#640)
Set initial value of mdProgressCircle as undefined, set value as undefined when mode is set to indeterminate.
1 parent 31f0c7f commit a5944da

File tree

2 files changed

+46
-9
lines changed

2 files changed

+46
-9
lines changed

src/components/progress-circle/progress-circle.spec.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,36 @@ describe('MdProgressCircular', () => {
4242
});
4343
});
4444

45-
it('should define a default value for the value attribute', (done: () => void) => {
45+
it('should define a default value of undefined for the value attribute', (done: () => void) => {
4646
builder
4747
.overrideTemplate(TestApp, '<md-progress-circle></md-progress-circle>')
4848
.createAsync(TestApp)
4949
.then((fixture) => {
5050
fixture.detectChanges();
5151
let progressElement = getChildDebugElement(fixture.debugElement, 'md-progress-circle');
52-
expect(progressElement.componentInstance.value).toBe(0);
52+
expect(progressElement.componentInstance.value).toBeUndefined();
5353
done();
5454
});
5555
});
5656

57+
it('should set the value to undefined when the mode is set to indeterminate',
58+
(done: () => void) => {
59+
builder
60+
.overrideTemplate(TestApp, `<md-progress-circle value="50"
61+
[mode]="mode"></md-progress-circle>`)
62+
.createAsync(TestApp)
63+
.then((fixture) => {
64+
let progressElement = getChildDebugElement(fixture.debugElement, 'md-progress-circle');
65+
fixture.debugElement.componentInstance.mode = 'determinate';
66+
fixture.detectChanges();
67+
expect(progressElement.componentInstance.value).toBe(50);
68+
fixture.debugElement.componentInstance.mode = 'indeterminate';
69+
fixture.detectChanges();
70+
expect(progressElement.componentInstance.value).toBe(undefined);
71+
done();
72+
});
73+
});
74+
5775
it('should clamp the value of the progress between 0 and 100', (done: () => void) => {
5876
builder
5977
.overrideTemplate(TestApp, '<md-progress-circle></md-progress-circle>')

src/components/progress-circle/progress-circle.ts

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ type EasingFn = (currentTime: number, startValue: number,
3535
selector: 'md-progress-circle',
3636
host: {
3737
'role': 'progressbar',
38-
'aria-valuemin': '0',
39-
'aria-valuemax': '100',
38+
'[attr.aria-valuemin]': 'ariaValueMin',
39+
'[attr.aria-valuemax]': 'ariaValueMax',
4040
},
4141
templateUrl: 'progress-circle.html',
4242
styleUrls: ['progress-circle.css'],
@@ -49,6 +49,22 @@ export class MdProgressCircle implements OnDestroy {
4949
/** The id of the indeterminate interval. */
5050
private _interdeterminateInterval: number;
5151

52+
/**
53+
* Values for aria max and min are only defined as numbers when in a determinate mode. We do this
54+
* because voiceover does not report the progress indicator as indeterminate if the aria min
55+
* and/or max value are number values.
56+
*
57+
* @internal
58+
*/
59+
get ariaValueMin() {
60+
return this.mode == 'determinate' ? 0 : null;
61+
}
62+
63+
/** @internal */
64+
get ariaValueMax() {
65+
return this.mode == 'determinate' ? 100 : null;
66+
}
67+
5268
/** @internal */
5369
get interdeterminateInterval() {
5470
return this._interdeterminateInterval;
@@ -79,19 +95,21 @@ export class MdProgressCircle implements OnDestroy {
7995
/**
8096
* Value of the progress circle.
8197
*
82-
* Input:number, defaults to 0.
98+
* Input:number
8399
* _value is bound to the host as the attribute aria-valuenow.
84100
*/
85-
private _value: number = 0;
101+
private _value: number;
86102
@Input()
87103
@HostBinding('attr.aria-valuenow')
88104
get value() {
89-
return this._value;
105+
if (this.mode == 'determinate') {
106+
return this._value;
107+
}
90108
}
91109
set value(v: number) {
92-
if (v) {
110+
if (v && this.mode == 'determinate') {
93111
let newValue = clamp(v);
94-
this._animateCircle(this.value, newValue, linearEase, DURATION_DETERMINATE, 0);
112+
this._animateCircle((this.value || 0), newValue, linearEase, DURATION_DETERMINATE, 0);
95113
this._value = newValue;
96114
}
97115
}
@@ -206,6 +224,7 @@ export class MdProgressCircle implements OnDestroy {
206224
selector: 'md-spinner',
207225
host: {
208226
'role': 'progressbar',
227+
'mode': 'indeterminate',
209228
},
210229
templateUrl: 'progress-circle.html',
211230
styleUrls: ['progress-circle.css'],

0 commit comments

Comments
 (0)