@@ -105,7 +105,7 @@ export class IgxIconService {
105105 * this.iconService.addSvgIcon('aruba', '/assets/svg/country_flags/aruba.svg', 'svg-flags');
106106 * ```
107107 */
108- public addSvgIcon ( name : string , url : string , family = this . _family ) {
108+ public addSvgIcon ( name : string , url : string , family = this . _family , stripMeta = false ) {
109109 if ( name && url ) {
110110 const safeUrl = this . _sanitizer . bypassSecurityTrustResourceUrl ( url ) ;
111111 if ( ! safeUrl ) {
@@ -119,7 +119,7 @@ export class IgxIconService {
119119
120120 if ( ! this . isSvgIconCached ( name , family ) ) {
121121 this . fetchSvg ( url ) . subscribe ( ( res ) => {
122- this . cacheSvgIcon ( name , res , family ) ;
122+ this . cacheSvgIcon ( name , res , family , stripMeta ) ;
123123 this . _iconLoaded . next ( { name, value : res , family } ) ;
124124 } ) ;
125125 }
@@ -135,13 +135,13 @@ export class IgxIconService {
135135 * <path d="M74 74h54v54H74" /></svg>', 'svg-flags');
136136 * ```
137137 */
138- public addSvgIconFromText ( name : string , iconText : string , family : string = '' ) {
138+ public addSvgIconFromText ( name : string , iconText : string , family : string = '' , stripMeta = false ) {
139139 if ( name && iconText ) {
140- if ( this . isSvgIconCached ( name , family ) ) {
140+ if ( this . isSvgIconCached ( name , family ) ) {
141141 return ;
142142 }
143143
144- this . cacheSvgIcon ( name , iconText , family ) ;
144+ this . cacheSvgIcon ( name , iconText , family , stripMeta ) ;
145145 } else {
146146 throw new Error ( 'You should provide at least `name` and `iconText` to register an svg icon.' ) ;
147147 }
@@ -155,7 +155,7 @@ export class IgxIconService {
155155 */
156156 public isSvgIconCached ( name : string , family : string = '' ) : boolean {
157157 const familyClassName = this . familyClassName ( family ) ;
158- if ( this . _cachedSvgIcons . has ( familyClassName ) ) {
158+ if ( this . _cachedSvgIcons . has ( familyClassName ) ) {
159159 const familyRegistry = this . _cachedSvgIcons . get ( familyClassName ) as Map < string , SafeHtml > ;
160160 return familyRegistry . has ( name ) ;
161161 }
@@ -185,7 +185,9 @@ export class IgxIconService {
185185 /**
186186 * @hidden
187187 */
188- private cacheSvgIcon ( name : string , value : string , family : string = '' ) {
188+ private cacheSvgIcon ( name : string , value : string , family = this . _family , stripMeta : boolean ) {
189+ family = ! ! family ? family : this . _family ;
190+
189191 if ( name && value ) {
190192 const doc = this . _domParser . parseFromString ( value , 'image/svg+xml' ) ;
191193 const svg = doc . querySelector ( 'svg' ) as SVGElement ;
@@ -197,6 +199,20 @@ export class IgxIconService {
197199 if ( svg ) {
198200 svg . setAttribute ( 'fit' , '' ) ;
199201 svg . setAttribute ( 'preserveAspectRatio' , 'xMidYMid meet' ) ;
202+
203+ if ( stripMeta ) {
204+ const title = svg . querySelector ( 'title' ) ;
205+ const desc = svg . querySelector ( 'desc' ) ;
206+
207+ if ( title ) {
208+ svg . removeChild ( title ) ;
209+ }
210+
211+ if ( desc ) {
212+ svg . removeChild ( desc ) ;
213+ }
214+ }
215+
200216 const safeSvg = this . _sanitizer . bypassSecurityTrustHtml ( svg . outerHTML ) ;
201217 this . _cachedSvgIcons . get ( family ) . set ( name , safeSvg ) ;
202218 }
0 commit comments