Skip to content

Commit 9d929d8

Browse files
committed
fix(live-announcer): avoid triggering a reflow when reading directive content
Uses `textContent`, instead of `innerText`, to avoid triggering a reflow when reading off the content of the directive element.
1 parent c5cfede commit 9d929d8

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,16 @@ export class CdkAriaLive implements OnDestroy {
117117
this._subscription.unsubscribe();
118118
this._subscription = null;
119119
}
120-
} else {
121-
if (!this._subscription) {
122-
this._subscription = this._ngZone.runOutsideAngular(
123-
() => this._contentObserver.observe(this._elementRef.nativeElement).subscribe(
124-
() => this._liveAnnouncer.announce(
125-
this._elementRef.nativeElement.innerText, this._politeness)));
126-
}
120+
} else if (!this._subscription) {
121+
this._subscription = this._ngZone.runOutsideAngular(() => {
122+
return this._contentObserver
123+
.observe(this._elementRef.nativeElement)
124+
.subscribe(() => {
125+
// Note that we use textContent here, rather than innerText, in order to avoid a reflow.
126+
const element = this._elementRef.nativeElement;
127+
this._liveAnnouncer.announce(element.textContent, this._politeness);
128+
});
129+
});
127130
}
128131
}
129132
private _politeness: AriaLivePoliteness = 'off';

0 commit comments

Comments
 (0)