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

Uses `textContent`, instead of `innerText`, to avoid triggering a reflow when reading off the content of the directive element.
  • Loading branch information
crisbeto committed Aug 11, 2018
1 parent c5cfede commit 9d929d8
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/cdk/a11y/live-announcer/live-announcer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,16 @@ export class CdkAriaLive implements OnDestroy {
this._subscription.unsubscribe();
this._subscription = null;
}
} else {
if (!this._subscription) {
this._subscription = this._ngZone.runOutsideAngular(
() => this._contentObserver.observe(this._elementRef.nativeElement).subscribe(
() => this._liveAnnouncer.announce(
this._elementRef.nativeElement.innerText, this._politeness)));
}
} else if (!this._subscription) {
this._subscription = this._ngZone.runOutsideAngular(() => {
return this._contentObserver
.observe(this._elementRef.nativeElement)
.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 9d929d8

Please sign in to comment.