Skip to content

Commit

Permalink
fix(live-announcer): avoid triggering a reflow when reading directive…
Browse files Browse the repository at this point in the history
… content (#12638)

Uses `textContent`, instead of `innerText`, to avoid triggering a reflow when reading off the content of the directive element.
  • Loading branch information
crisbeto authored and jelbourn committed Aug 29, 2018
1 parent b0555b5 commit 92f53ce
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/cdk/a11y/live-announcer/live-announcer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,15 @@ export class CdkAriaLive implements OnDestroy {
this._subscription = null;
}
} else if (!this._subscription) {
this._subscription = this._ngZone.runOutsideAngular(
() => this._contentObserver.observe(this._elementRef).subscribe(
() => this._liveAnnouncer.announce(
this._elementRef.nativeElement.innerText, this._politeness)));
this._subscription = this._ngZone.runOutsideAngular(() => {
return this._contentObserver
.observe(this._elementRef)
.subscribe(() => {
// Note that we use textContent here, rather than innerText, in order to avoid a reflow.
const element = this._elementRef.nativeElement;
this._liveAnnouncer.announce(element.textContent, this._politeness);
});
});
}
}
private _politeness: AriaLivePoliteness = 'off';
Expand Down

0 comments on commit 92f53ce

Please sign in to comment.