Skip to content

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

Merged
merged 1 commit into from
Jun 28, 2018

Conversation

crisbeto
Copy link
Member

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 #11151.

@crisbeto crisbeto requested a review from jelbourn as a code owner June 27, 2018 19:52
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Jun 27, 2018
@crisbeto crisbeto added the target: patch This PR is targeted for the next patch release label Jun 27, 2018
@@ -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;
Copy link
Member

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];

Copy link
Member

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.

@crisbeto crisbeto force-pushed the 11151/icon-clearing-content branch from c75a562 to ba89487 Compare June 27, 2018 20:51
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.
@crisbeto crisbeto force-pushed the 11151/icon-clearing-content branch from ba89487 to 92a76e7 Compare June 27, 2018 20:51
@crisbeto
Copy link
Member Author

Addressed the feedback.

Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jelbourn jelbourn added pr: lgtm action: merge The PR is ready for merge by the caretaker labels Jun 27, 2018
@josephperrott josephperrott merged commit 8280a76 into angular:master Jun 28, 2018
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Badge not showing on mat-icon if using svgIcon
4 participants