@@ -9,7 +9,7 @@ import {coerceNumberProperty, NumberInput} from '@angular/cdk/coercion';
9
9
import { DOCUMENT } from '@angular/common' ;
10
10
import {
11
11
AfterViewInit ,
12
- ChangeDetectionStrategy ,
12
+ ChangeDetectionStrategy , ChangeDetectorRef ,
13
13
Component ,
14
14
ElementRef ,
15
15
EventEmitter ,
@@ -26,8 +26,8 @@ import {
26
26
} from '@angular/core' ;
27
27
import { CanColor , CanColorCtor , mixinColor } from '@angular/material/core' ;
28
28
import { ANIMATION_MODULE_TYPE } from '@angular/platform-browser/animations' ;
29
- import { fromEvent , Observable , Subscription } from 'rxjs' ;
30
- import { filter } from 'rxjs/operators' ;
29
+ import { fromEvent , Observable , Subject , Subscription } from 'rxjs' ;
30
+ import { filter , takeUntil } from 'rxjs/operators' ;
31
31
32
32
33
33
// TODO(josephperrott): Benchpress tests.
@@ -82,6 +82,18 @@ export type ProgressBarMode = 'determinate' | 'indeterminate' | 'buffer' | 'quer
82
82
/** Counter used to generate unique IDs for progress bars. */
83
83
let progressbarId = 0 ;
84
84
85
+
86
+ function readAriaValues ( element : HTMLElement ) : Observable < string > {
87
+ const config = { attributeFilter : [ 'aria-label' ] } ;
88
+ return new Observable ( ( observer ) => {
89
+ const mutation = new MutationObserver ( ( mutations ) => {
90
+ const newLabel = ( mutations [ 0 ] . target as HTMLElement ) . getAttribute ( 'aria-label' ) ?? '' ;
91
+ observer . next ( newLabel ) ;
92
+ } ) ;
93
+ mutation . observe ( element , config ) ;
94
+ } ) ;
95
+ }
96
+
85
97
/**
86
98
* `<mat-progress-bar>` component.
87
99
*/
@@ -92,7 +104,6 @@ let progressbarId = 0;
92
104
'role' : 'progressbar' ,
93
105
'aria-valuemin' : '0' ,
94
106
'aria-valuemax' : '100' ,
95
- '[attr.aria-label]' : 'ariaLabel' ,
96
107
'[attr.aria-valuenow]' : '(mode === "indeterminate" || mode === "query") ? null : value' ,
97
108
'[attr.mode]' : 'mode' ,
98
109
'class' : 'mat-progress-bar' ,
@@ -125,14 +136,22 @@ export class MatProgressBar extends _MatProgressBarMixinBase implements CanColor
125
136
const path = location ? location . getPathname ( ) . split ( '#' ) [ 0 ] : '' ;
126
137
this . _rectangleFillValue = `url('${ path } #${ this . progressbarId } ')` ;
127
138
this . _isNoopAnimation = _animationMode === 'NoopAnimations' ;
139
+ const mutationObservable = readAriaValues ( _elementRef . nativeElement ) ;
140
+
141
+ mutationObservable . pipe ( takeUntil ( this . _destroyed ) ) . subscribe ( ( label ) => {
142
+ console . log ( label , this . value ) ;
143
+ const accessibleLabel = ( _elementRef . nativeElement as HTMLElement )
144
+ . getElementsByClassName ( 'mat-progress-bar-accessible-label__label' ) ! [ 0 ] ;
145
+ accessibleLabel . innerHTML = label ;
146
+ } ) ;
128
147
}
129
148
149
+ /** Subject that emits when the component has been destroyed. */
150
+ protected _destroyed = new Subject < void > ( ) ;
151
+
130
152
/** Flag that indicates whether NoopAnimations mode is set to true. */
131
153
_isNoopAnimation = false ;
132
154
133
- /** aria-label of progress bar to be set on the host. */
134
- @Input ( 'aria-label' ) ariaLabel : string = '' ;
135
-
136
155
/** Value of the progress bar. Defaults to zero. Mirrored to aria-valuenow. */
137
156
@Input ( )
138
157
get value ( ) : number { return this . _value ; }
@@ -213,6 +232,9 @@ export class MatProgressBar extends _MatProgressBarMixinBase implements CanColor
213
232
214
233
ngOnDestroy ( ) {
215
234
this . _animationEndSubscription . unsubscribe ( ) ;
235
+
236
+ this . _destroyed . next ( ) ;
237
+ this . _destroyed . complete ( ) ;
216
238
}
217
239
218
240
static ngAcceptInputType_value : NumberInput ;
0 commit comments