angular / components

Component infrastructure and Material Design components for Angular
https://material.angular.io
MIT License
24.22k stars 6.69k forks source link

Some Mat SVG Icons disappear on mat-sidenav close #16467

Open ar27111994 opened 5 years ago

ar27111994 commented 5 years ago

Reproduction

Use StackBlitz to reproduce your issue: https://stackblitz.com/edit/angular-7-master-svg1

Steps to reproduce:

  1. Setup shared components for svg icon, sidebar content and page content alongside the ability to toggle mat-sidenav.
  2. Toggle Sidenav and see all svg icons on the page get disappeared on sidenav close and re-appear on sidenav open.

Expected Behavior

No svg icon should disappear from the page.

Actual Behavior

Toggling Sidenav makes all svg icons on the page disappear on sidenav close and re-appear on sidenav open. Moreover, if you inspect the html output of page and components, you will see that svg icons are still present there, with no change in attributes, html, etc. Furthermore, this bug happens with some icons only (not sure what is the differentiator as there's dozens of icons in our locally under-development app that exhibit this weird bug, but there are also some that don't), for example, svg icon in this stackblitz works correctly. https://stackblitz.com/edit/angular-7-master-svg2

Environment

sunil512 commented 5 years ago

That is the problem with your SVG. Try with a different SVG it is working, you can find SVG's in flaticon.

ar27111994 commented 5 years ago

@sunil512 maybe yes, but why does this problem occur only with material components like mat-sidenav and mat-expansion-panel (tested locally just now)?

crisbeto commented 4 years ago

I think it's because there are references by ID in the SVGs and since there are multiple elements with the same ID on the page, the browser picks up the first one in the DOM. When the sidenav is hidden those elements also become hidden which makes them disappear in the other usages.

ar27111994 commented 4 years ago

@crisbeto ok I have updated my 2nd (working) example with a svg with multiple elements having an id assigned to them and as you can see, its working correctly despite having multiple ids. So I think its not an issue with ids

sunil512 commented 4 years ago

@ar27111994 That is because of some CSS classes in the SVG, those classes contains props overflow: visible and hidden. The browser picks up them and updating in the dom. If you check clearly, a no - transition class is adding to the sidenav which contains the overflow: hidden/visible prop, that property is in the SVG code which is updating first in the DOM.

ar27111994 commented 4 years ago

@sunil512 if I understand correctly, there shouldn't be any overflow related attributes or css properties in svgs. If yes, then I have removed them from first stackblitz svg, but the problem still persists, moreover, our local svgs which produce this bug also don't have any overflow properties/css styles, so I am not sure what is the problem.

likeatobo commented 4 years ago

I am experiencing the same weird behaviour. This is how my svg looks like:

<svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg"><g clip-path="url(#clip0)"><path d="M16 32c8.837 0 16-7.163 16-16S24.837 0 16 0 0 7.163 0 16s7.163 16 16 16z" fill="#06F"/><path d="M13 25h-.03c-.3-.01-.59-.16-.77-.4l-6-8c-.33-.44-.24-1.07.2-1.4.44-.33 1.07-.24 1.4.2l5.25 7L24.24 9.35a.999.999 0 111.52 1.3l-12 14c-.19.22-.47.35-.76.35z" fill="#fff"/></g><defs><clipPath id="clip0"><path fill="#fff" d="M0 0h32v32H0z"/></clipPath></defs></svg>

All the svgs with clipPath behave like that.

dawda92 commented 4 years ago

I'm facing the same problem - Does anyone have a solution so far?

likeatobo commented 4 years ago

@dawda92 After struggling for a long time I just did a workaround which solved it for me and caused no other problems so far. Maybe this helps you as well.

  mat-sidenav {
    visibility: unset !important;
  }

https://stackblitz.com/edit/angular-svg-bug If you remove the code from styles.scss you can see that it is not working anymore

ar27111994 commented 4 years ago

yes @likeatobo that seems to work in my above stackblitz too. Thanks.

mmart1n commented 2 months ago

I believe that the issue is related to this: https://stackoverflow.com/questions/78305598/infinite-ngx-slick-carousel-with-mat-icons-svg-content-disappear. Stackblitz to reproduce: https://stackblitz.com/edit/c8cxxh