-
Notifications
You must be signed in to change notification settings - Fork 6.8k
fix(icon): clearing all content when inserting a new SVG #11956
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(icon): clearing all content when inserting a new SVG #11956
Conversation
src/lib/icon/icon.ts
Outdated
@@ -198,11 +206,16 @@ export class MatIcon extends _MatIconMixinBase implements OnChanges, OnInit, Can | |||
private _clearSvgElement() { | |||
const layoutElement: HTMLElement = this._elementRef.nativeElement; | |||
const childCount = layoutElement.childNodes.length; | |||
const elementNodeType = this._document ? this._document.ELEMENT_NODE : 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is the only thing document is needed for, I'm fine with just hard-coding 1
with a comment
for (let i = 0; i < childCount; i++) { | ||
layoutElement.removeChild(layoutElement.childNodes[i]); | ||
const child = layoutElement.childNodes[i]; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to add a comment that elaborates on why only specific elements are removed.
c75a562
to
ba89487
Compare
Currently when we insert a new SVG icon, we clear the entire content of the `mat-icon` in order to get rid of the previous icon. This is problematic, because it ends up removing other elements like `mat-badge`. These changes switch to removing all non-element nodes and all SVGs. Fixes angular#11151.
ba89487
to
92a76e7
Compare
Addressed the feedback. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Currently when we insert a new SVG icon, we clear the entire content of the
mat-icon
in order to get rid of the previous icon. This is problematic, because it ends up removing other elements likemat-badge
. These changes switch to removing all non-element nodes and all SVGs.Fixes #11151.