File tree Expand file tree Collapse file tree 2 files changed +11
-8
lines changed
src/cdk/a11y/live-announcer Expand file tree Collapse file tree 2 files changed +11
-8
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,6 @@ import {By} from '@angular/platform-browser';
5
5
import { A11yModule } from '../index' ;
6
6
import { LiveAnnouncer } from './live-announcer' ;
7
7
import { LIVE_ANNOUNCER_ELEMENT_TOKEN } from './live-announcer-token' ;
8
- import Spy = jasmine . Spy ;
9
8
10
9
11
10
describe ( 'LiveAnnouncer' , ( ) => {
@@ -116,7 +115,7 @@ describe('LiveAnnouncer', () => {
116
115
describe ( 'CdkAriaLive' , ( ) => {
117
116
let mutationCallbacks : Function [ ] = [ ] ;
118
117
let announcer : LiveAnnouncer ;
119
- let announcerSpy : Spy ;
118
+ let announcerSpy : jasmine . Spy ;
120
119
let fixture : ComponentFixture < DivWithCdkAriaLive > ;
121
120
122
121
const invokeMutationCallbacks = ( ) => mutationCallbacks . forEach ( cb => cb ( ) ) ;
@@ -128,7 +127,7 @@ describe('CdkAriaLive', () => {
128
127
providers : [ {
129
128
provide : MutationObserverFactory ,
130
129
useValue : {
131
- create : function ( callback : Function ) {
130
+ create : ( callback : Function ) => {
132
131
mutationCallbacks . push ( callback ) ;
133
132
134
133
return {
Original file line number Diff line number Diff line change @@ -92,9 +92,11 @@ export class LiveAnnouncer implements OnDestroy {
92
92
* with a wider range of browsers and screen readers.
93
93
*/
94
94
@Directive ( {
95
- selector : '[cdkAriaLive]'
95
+ selector : '[cdkAriaLive]' ,
96
+ exportAs : 'cdkAriaLive' ,
96
97
} )
97
98
export class CdkAriaLive implements OnDestroy {
99
+ /** The aria-live politeness level to use when announcing messages. */
98
100
@Input ( 'cdkAriaLive' )
99
101
get politeness ( ) : AriaLivePoliteness { return this . _politeness ; }
100
102
set politeness ( value : AriaLivePoliteness ) {
@@ -105,10 +107,12 @@ export class CdkAriaLive implements OnDestroy {
105
107
this . _subscription = null ;
106
108
}
107
109
} else {
108
- this . _subscription = this . _ngZone . runOutsideAngular (
109
- ( ) => this . _contentObserver . observe ( this . _elementRef . nativeElement ) . subscribe (
110
- ( ) => this . _liveAnnouncer . announce (
111
- this . _elementRef . nativeElement . innerText , this . _politeness ) ) ) ;
110
+ if ( ! this . _subscription ) {
111
+ this . _subscription = this . _ngZone . runOutsideAngular (
112
+ ( ) => this . _contentObserver . observe ( this . _elementRef . nativeElement ) . subscribe (
113
+ ( ) => this . _liveAnnouncer . announce (
114
+ this . _elementRef . nativeElement . innerText , this . _politeness ) ) ) ;
115
+ }
112
116
}
113
117
}
114
118
private _politeness : AriaLivePoliteness = 'off' ;
You can’t perform that action at this time.
0 commit comments