Skip to content
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

Open
delilahw opened this issue Nov 7, 2024 · 0 comments
Open

Inconsistent viewBox attribute in <svg/> elements #249

delilahw opened this issue Nov 7, 2024 · 0 comments

Comments

@delilahw
Copy link

delilahw commented Nov 7, 2024

What version of astro-icon are you using?

v1.1.2

Astro Info

Astro                    v4.16.10
Node                     v18.20.3
System                   Linux (x64)
Package Manager          unknown
Output                   static
Adapter                  none
Integrations             astro-icon

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 their viewBox attribute, which is inconsistent behaviour.

That is,

{/* Put both of these `<Icon/>` instances, one after another, in the same Astro file: */}

{/* This renders `<svg/>` _without_ a `viewBox` attribute */}
<Icon name="square"/>

{/* This renders `<svg/>` _with_ a `viewBox` attribute */}
<Icon name="square"/>

I suspect the cause to be: includeSymbol: bool determines whether to remove the viewBox attribute. According to the below assignment, it will be false in subsequent usages of <Icon/> because i > 0.

const includeSymbol = !inline && i === 0;

const { viewBox } = normalizedProps;
if (includeSymbol) {
delete normalizedProps.viewBox;
}
---
<svg {...normalizedProps} data-icon={name}>


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 the viewBox 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant