Skip to content

Commit 589d7a5

Browse files
committed
fix(icon): IE/Edge ignoring style tags inside inline SVG
Adds a workaround for an issue in IE11 and Edge where `style` tags inside dynamically-created SVGs will be ignored. Fixes #11458.
1 parent 9062640 commit 589d7a5

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/lib/icon/icon.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,16 @@ export class MatIcon extends _MatIconMixinBase implements OnChanges, OnInit, Can
182182

183183
private _setSvgElement(svg: SVGElement) {
184184
this._clearSvgElement();
185+
186+
// Workaround for IE11 and Edge ignoring `style` tags inside dynamically-created SVGs.
187+
// See: https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/10898469/
188+
// Do this before inserting the element into the DOM, in order to avoid a style recalculation.
189+
const styleTags = svg.querySelectorAll('style') as NodeListOf<HTMLStyleElement>;
190+
191+
for (let i = 0; i < styleTags.length; i++) {
192+
styleTags[i].textContent += ' ';
193+
}
194+
185195
this._elementRef.nativeElement.appendChild(svg);
186196
}
187197

0 commit comments

Comments
 (0)