-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Mat Icon doesn't encapsulate svg styles #12926
Comments
This is working as intended. All of the Angular Material components are |
So it is not recommended to have styles within an SVG? Forgive my ignorance as I've done very little with SVG's but the SVG's in question (for this scenario) came directly from our designers. Are you saying that SVG's should be cleansed of all inline CSS and every SVG that requires some type of style be done within its own file? I guess in my scenario, I could just move it out of the Also, is there any way to use a different ViewEncapsulation on the MatIcon Component? |
The view encapsulation cannot be changed downstream. I would personally recommend avoiding inline styles inside an SVG element if you plan on inlining the SVG. |
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. |
Bug, feature request, or proposal:
Bug? Maybe a proposal?
What is the expected behavior?
SVG Icons that are added to the matIconRegistry should have isolated styles. Currently, I have some SVG's that have some inline css and when I add them to a page using the
<mat-icon svgIcon="<name>"></mat-icon>
it overwrites other styles on the page. This shouldn't happen. The styling in the svg should only work within the mat-icon and not touch other things outside of it.What is the current behavior?
Inline CSS within an SVG that is added to the mat-icon registry overwrittes other mat-icons/styles on the page.
What are the steps to reproduce?
Providing a StackBlitz reproduction is the best way to share your issue.
StackBlitz starter: https://goo.gl/wwnhMV
I would love to provide a stackblitz for this but stackblitz won't let me add an svg icon.
1.) Create 2 svg files with some inline css (example below)
2.) Add it to the MatIconRegistry
3.) Render both svg's on a page using the
<mat-icon svgIcon="<name>"></mat-icon>
syntaxNotice how svg icon #1 overwrites svg icon #2
What is the use-case or motivation for changing an existing behavior?
It shouldn't do this. If you add the SVG Icon using
object
orimg
, it works just fine.Which versions of Angular, Material, OS, TypeScript, browsers are affected?
Currently on version 6.1 but present in all versions that I've worked with.
Is there anything else we should know?
SVG Icon #1:
SVG Icon #2:
app.module.ts:
component.html:
<mat-icon svgIcon="svg1"></mat-icon>
<mat-icon svgIcon="svg2"></mat-icon>
The text was updated successfully, but these errors were encountered: