@@ -105,7 +105,7 @@ export class IgxIconService {
105
105
* this.iconService.addSvgIcon('aruba', '/assets/svg/country_flags/aruba.svg', 'svg-flags');
106
106
* ```
107
107
*/
108
- public addSvgIcon ( name : string , url : string , family = this . _family ) {
108
+ public addSvgIcon ( name : string , url : string , family = this . _family , stripMeta = false ) {
109
109
if ( name && url ) {
110
110
const safeUrl = this . _sanitizer . bypassSecurityTrustResourceUrl ( url ) ;
111
111
if ( ! safeUrl ) {
@@ -119,7 +119,7 @@ export class IgxIconService {
119
119
120
120
if ( ! this . isSvgIconCached ( name , family ) ) {
121
121
this . fetchSvg ( url ) . subscribe ( ( res ) => {
122
- this . cacheSvgIcon ( name , res , family ) ;
122
+ this . cacheSvgIcon ( name , res , family , stripMeta ) ;
123
123
this . _iconLoaded . next ( { name, value : res , family } ) ;
124
124
} ) ;
125
125
}
@@ -135,13 +135,13 @@ export class IgxIconService {
135
135
* <path d="M74 74h54v54H74" /></svg>', 'svg-flags');
136
136
* ```
137
137
*/
138
- public addSvgIconFromText ( name : string , iconText : string , family : string = '' ) {
138
+ public addSvgIconFromText ( name : string , iconText : string , family : string = '' , stripMeta = false ) {
139
139
if ( name && iconText ) {
140
- if ( this . isSvgIconCached ( name , family ) ) {
140
+ if ( this . isSvgIconCached ( name , family ) ) {
141
141
return ;
142
142
}
143
143
144
- this . cacheSvgIcon ( name , iconText , family ) ;
144
+ this . cacheSvgIcon ( name , iconText , family , stripMeta ) ;
145
145
} else {
146
146
throw new Error ( 'You should provide at least `name` and `iconText` to register an svg icon.' ) ;
147
147
}
@@ -155,7 +155,7 @@ export class IgxIconService {
155
155
*/
156
156
public isSvgIconCached ( name : string , family : string = '' ) : boolean {
157
157
const familyClassName = this . familyClassName ( family ) ;
158
- if ( this . _cachedSvgIcons . has ( familyClassName ) ) {
158
+ if ( this . _cachedSvgIcons . has ( familyClassName ) ) {
159
159
const familyRegistry = this . _cachedSvgIcons . get ( familyClassName ) as Map < string , SafeHtml > ;
160
160
return familyRegistry . has ( name ) ;
161
161
}
@@ -185,7 +185,9 @@ export class IgxIconService {
185
185
/**
186
186
* @hidden
187
187
*/
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
+
189
191
if ( name && value ) {
190
192
const doc = this . _domParser . parseFromString ( value , 'image/svg+xml' ) ;
191
193
const svg = doc . querySelector ( 'svg' ) as SVGElement ;
@@ -197,6 +199,20 @@ export class IgxIconService {
197
199
if ( svg ) {
198
200
svg . setAttribute ( 'fit' , '' ) ;
199
201
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
+
200
216
const safeSvg = this . _sanitizer . bypassSecurityTrustHtml ( svg . outerHTML ) ;
201
217
this . _cachedSvgIcons . get ( family ) . set ( name , safeSvg ) ;
202
218
}
0 commit comments