cereschen / vite-plugin-svg-sprite-component

7 stars 4 forks source link

width and height attribute inside svg has been removed #7

Closed liho00 closed 3 years ago

liho00 commented 3 years ago

current behavior: I understand that height and width attributes are removed by default on the svg tag, Its correct.

image

Expected behavior: However, I got image tag inside the svg tag, the width and height attributes are removed by default. The missing of the inner width and height attributes caused the svg broken. So, i think we should only remove the width and height attribute only on svg tag instead of all width and height attribute in the svg file.

liho00 commented 3 years ago

My current solution is svgSpritePlugin({ symbolId: (name) => "icon-" + name, removeAttrs: [] }), removeAttrs set as empty array, and then manually go to the svg file remove only the width and height attributes on the svg tag.

cereschen commented 3 years ago

Hi @liho00 I'm not sure if removing just the width and height of the SVG tag will cause new problems, so I plan to expose a function that lets users handle the elements themselves. What do you think

liho00 commented 3 years ago

Hi @liho00 I'm not sure if removing just the width and height of the SVG tag will cause new problems, so I plan to expose a function that lets users handle the elements themselves. What do you think

Removing the width and height attributes Tag isn't a problem and is correct (hence the SVG width & height can be controlled by class and style), I also encourage to do so. However, it shouldn't remove the inner Tags with width and height attributes.

I think it is only necessary to fix the removing function, which only removes the width and height attributes of the SVG tag, other tags shall not be affected.

cereschen commented 3 years ago

Now just remove the width and height from the root element. At the same time, I added the transform option. We can modify elements more freely

liho00 commented 3 years ago

Well done sir!