-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Icons: Remove width / height attributes from svg element #43747
base: trunk
Are you sure you want to change the base?
Conversation
Size Change: -67 B (0%) Total Size: 1.84 MB
ℹ️ View Unchanged
|
Hi, thank you for the PR! I'm actually not sure this is a good idea, and on the contrary it's my main instinct that all of our icons should have preset width and heights baked in. For two reasons:
The 2nd issue is the most important one, especially in the site editor where the CSS can take a bit longer to load, causing a flash of a big icon. We recently fixed this for the spinner. You can see the flash of a big spinner here: #43226 Obviously the What do you think? |
cc @mirka |
That makes sense, since icons from the Icons library might be used directly without going through the component. I went back through the history of the Icons package and couldn't find any clear argument or reason why almost all icons don't have Is your suggestion to give |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's fine to assume that the SVGs in our icon library will always be used via the Icon component.
The Icon component adds width/height attributes to the SVG based on the size
prop, so in reality the SVGs will have a set width/height at render time, regardless of whether the original SVG code includes it. So if we can assume that icon SVGs will be used via Icon
, we don't have to worry about the icon files themselves having a width/height attribute.
The main bug here is that the width/height set by the Icon component will be overwritten again by the icon's built-in width/height 😄
gutenberg/packages/components/src/icon/index.tsx
Lines 85 to 87 in 9581694
width: size, | |
height: size, | |
...icon.props, |
Reverse this order and we're good 👍
Thanks for identifying the bug! |
The issue of the Button |
929f326
to
4722a0c
Compare
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Fix: #43745Related: #40315
What?
This PR removes the
width
/height
attributes from the svg element in the@wordpress/icons
icon.Why?
As tested in #43745, the
iconSize
prop is not applied when an icon withwidth
/height
attributes is specified in theButton
component.@edit: This issue is fixed by #43821.
We could not find a clear reason why the
Icons
component could resize these icons correctly, but at least the svg icons themselves don't needwidth
/height
, and removing these attributes gave the expected results.How?
Simply removed attributes.
Testing Instructions