@@ -17,23 +17,18 @@ import {
1717 OnDestroy ,
1818 inject ,
1919 DOCUMENT ,
20- SecurityContext ,
2120} from '@angular/core' ;
22- import { DomSanitizer , SafeHtml } from '@angular/platform-browser' ;
2321import { Subscription } from 'rxjs' ;
2422import {
2523 AriaLivePoliteness ,
2624 LiveAnnouncerDefaultOptions ,
2725 LIVE_ANNOUNCER_ELEMENT_TOKEN ,
2826 LIVE_ANNOUNCER_DEFAULT_OPTIONS ,
2927} from './live-announcer-tokens' ;
30- import { _CdkPrivateStyleLoader , _VisuallyHiddenLoader , trustedHTMLFromString } from '../../private' ;
28+ import { _CdkPrivateStyleLoader , _VisuallyHiddenLoader } from '../../private' ;
3129
3230let uniqueIds = 0 ;
3331
34- /** Possible types for a message that can be announced by the `LiveAnnouncer`. */
35- export type LiveAnnouncerMessage = string | SafeHtml ;
36-
3732@Injectable ( { providedIn : 'root' } )
3833export class LiveAnnouncer implements OnDestroy {
3934 private _ngZone = inject ( NgZone ) ;
@@ -43,7 +38,6 @@ export class LiveAnnouncer implements OnDestroy {
4338
4439 private _liveElement : HTMLElement ;
4540 private _document = inject ( DOCUMENT ) ;
46- private _sanitizer = inject ( DomSanitizer ) ;
4741 private _previousTimeout : ReturnType < typeof setTimeout > ;
4842 private _currentPromise : Promise < void > | undefined ;
4943 private _currentResolve : ( ( ) => void ) | undefined ;
@@ -60,15 +54,15 @@ export class LiveAnnouncer implements OnDestroy {
6054 * @param message Message to be announced to the screen reader.
6155 * @returns Promise that will be resolved when the message is added to the DOM.
6256 */
63- announce ( message : LiveAnnouncerMessage ) : Promise < void > ;
57+ announce ( message : string ) : Promise < void > ;
6458
6559 /**
6660 * Announces a message to screen readers.
6761 * @param message Message to be announced to the screen reader.
6862 * @param politeness The politeness of the announcer element.
6963 * @returns Promise that will be resolved when the message is added to the DOM.
7064 */
71- announce ( message : LiveAnnouncerMessage , politeness ?: AriaLivePoliteness ) : Promise < void > ;
65+ announce ( message : string , politeness ?: AriaLivePoliteness ) : Promise < void > ;
7266
7367 /**
7468 * Announces a message to screen readers.
@@ -78,7 +72,7 @@ export class LiveAnnouncer implements OnDestroy {
7872 * 100ms after `announce` has been called.
7973 * @returns Promise that will be resolved when the message is added to the DOM.
8074 */
81- announce ( message : LiveAnnouncerMessage , duration ?: number ) : Promise < void > ;
75+ announce ( message : string , duration ?: number ) : Promise < void > ;
8276
8377 /**
8478 * Announces a message to screen readers.
@@ -89,13 +83,9 @@ export class LiveAnnouncer implements OnDestroy {
8983 * 100ms after `announce` has been called.
9084 * @returns Promise that will be resolved when the message is added to the DOM.
9185 */
92- announce (
93- message : LiveAnnouncerMessage ,
94- politeness ?: AriaLivePoliteness ,
95- duration ?: number ,
96- ) : Promise < void > ;
86+ announce ( message : string , politeness ?: AriaLivePoliteness , duration ?: number ) : Promise < void > ;
9787
98- announce ( message : LiveAnnouncerMessage , ...args : any [ ] ) : Promise < void > {
88+ announce ( message : string , ...args : any [ ] ) : Promise < void > {
9989 const defaultOptions = this . _defaultOptions ;
10090 let politeness : AriaLivePoliteness | undefined ;
10191 let duration : number | undefined ;
@@ -137,22 +127,7 @@ export class LiveAnnouncer implements OnDestroy {
137127
138128 clearTimeout ( this . _previousTimeout ) ;
139129 this . _previousTimeout = setTimeout ( ( ) => {
140- if ( ! message || typeof message === 'string' ) {
141- this . _liveElement . textContent = message ;
142- } else {
143- const cleanMessage = this . _sanitizer . sanitize ( SecurityContext . HTML , message ) ;
144-
145- if ( cleanMessage === null && ( typeof ngDevMode === 'undefined' || ngDevMode ) ) {
146- throw new Error (
147- `The message provided to LiveAnnouncer was not trusted as safe HTML by ` +
148- `Angular's DomSanitizer. Attempted message was "${ message } ".` ,
149- ) ;
150- }
151-
152- this . _liveElement . innerHTML = trustedHTMLFromString (
153- cleanMessage || '' ,
154- ) as unknown as string ;
155- }
130+ this . _liveElement . textContent = message ;
156131
157132 if ( typeof duration === 'number' ) {
158133 this . _previousTimeout = setTimeout ( ( ) => this . clear ( ) , duration ) ;
0 commit comments