-
-
Notifications
You must be signed in to change notification settings - Fork 64
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
Inconsistent viewBox attribute in <svg/>
elements
#249
Comments
I think I'm experiencing this - the first |
@alxndrsn My current workaround is just pinning it to |
@delilahw thanks 🙂 I replaced it with a custom component: ---
import icnA from '../icons/a.svg?raw';
import icnB from '../icons/b.svg?raw';
...
export function htmlFrom(iconName) {
switch(iconName) {
case 'a': return icnA;
case 'b': return icnB;
...
default: return '<div>missing icon</div>';
}
}
const { src } = Astro.props;
const iconHtml = htmlFrom(src);
---
<Fragment set:html={iconHtml /*eslint-disable-line astro/no-set-html-directive*/}/> A bit annoying as every icon has to be added to the |
Apologies! I'll get this fixed soon! This stemmed from #212 |
InvestigationSo looking into this further. This is the current functionality in Why this happensThe Options to Address ItOption 1: Specify both
|
@delilahw @alxndrsn This library is going to be shifting to covering only iconify as we've merged the handling of SVG files primarily to Astro. Would love for you to test it out and provide some initial feedback! Please try upgrading to You can read the docs about it here: https://5-0-0-beta.docs.astro.build/en/reference/experimental-flags/svg/ You can provide feedback about it here: withastro/roadmap#1035 |
Glad I found this thread, as I was banging my head against the wall trying to figure out why the first instance of an svg icon looked right but subsequent ones didn't. @delilahw's suggestion of pinning to v1.1.1 fixes it, even with Astro v5.1.1. @stramel keep in mind that the In my case, I was using an icon that was flush up against the |
How the viewBox attribute is handled changed after v1.1.1, which caused the default icons used for blog posts with no photos to not look right in the previous push. More info: natemoo-re/astro-icon#249
What version of
astro-icon
are you using?v1.1.2
Astro Info
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
Hi! Thank you all for your work on this library, it's been super helpful in optimising icons and bringing them to my Astro site. 😇
In #246, the
viewBox
attribute was moved from<svg/>
to<symbol/>
. However, for non-inline icons, it appears that this only takes effect on the first occurrence of<Icon/>
. Subsequent instances of<Icon/>
retain theirviewBox
attribute, which is inconsistent behaviour.That is,
I suspect the cause to be:
includeSymbol: bool
determines whether to remove the viewBox attribute. According to the below assignment, it will befalse
in subsequent usages of<Icon/>
becausei > 0
.astro-icon/packages/core/components/Icon.astro
Line 39 in 531db17
astro-icon/packages/core/components/Icon.astro
Lines 118 to 124 in 531db17
What's the expected result?
The behaviour should be consistent. A consumer should be able to specify the same markup (
<Icon name="square"/>
) and expect them to render<svg/>
that behaves the same — it should either omit theviewBox
attribute across all instances, or include them across all instances.Another suggestion is to add some sort of attribute/config to let users decide the
viewBox
behaviour.Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-u6hdxa?file=src%2Fpages%2Findex.astro
The text was updated successfully, but these errors were encountered: