Skip to content

Commit fd80066

Browse files
committed
address comments
1 parent 57e2cd2 commit fd80066

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

src/cdk/a11y/live-announcer/live-announcer.spec.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {By} from '@angular/platform-browser';
55
import {A11yModule} from '../index';
66
import {LiveAnnouncer} from './live-announcer';
77
import {LIVE_ANNOUNCER_ELEMENT_TOKEN} from './live-announcer-token';
8-
import Spy = jasmine.Spy;
98

109

1110
describe('LiveAnnouncer', () => {
@@ -116,7 +115,7 @@ describe('LiveAnnouncer', () => {
116115
describe('CdkAriaLive', () => {
117116
let mutationCallbacks: Function[] = [];
118117
let announcer: LiveAnnouncer;
119-
let announcerSpy: Spy;
118+
let announcerSpy: jasmine.Spy;
120119
let fixture: ComponentFixture<DivWithCdkAriaLive>;
121120

122121
const invokeMutationCallbacks = () => mutationCallbacks.forEach(cb => cb());
@@ -128,7 +127,7 @@ describe('CdkAriaLive', () => {
128127
providers: [{
129128
provide: MutationObserverFactory,
130129
useValue: {
131-
create: function(callback: Function) {
130+
create: (callback: Function) => {
132131
mutationCallbacks.push(callback);
133132

134133
return {

src/cdk/a11y/live-announcer/live-announcer.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,11 @@ export class LiveAnnouncer implements OnDestroy {
9292
* with a wider range of browsers and screen readers.
9393
*/
9494
@Directive({
95-
selector: '[cdkAriaLive]'
95+
selector: '[cdkAriaLive]',
96+
exportAs: 'cdkAriaLive',
9697
})
9798
export class CdkAriaLive implements OnDestroy {
99+
/** The aria-live politeness level to use when announcing messages. */
98100
@Input('cdkAriaLive')
99101
get politeness(): AriaLivePoliteness { return this._politeness; }
100102
set politeness(value: AriaLivePoliteness) {
@@ -105,10 +107,12 @@ export class CdkAriaLive implements OnDestroy {
105107
this._subscription = null;
106108
}
107109
} 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+
}
112116
}
113117
}
114118
private _politeness: AriaLivePoliteness = 'off';

0 commit comments

Comments
 (0)