Conversation
This is an alternative to #10938 which for whatever reason I can't rebase. The purpose is the same: This PR fixes an icon size regression that was introduced in #9828. Basically SVG icons are _between 20 and 24px_. If an SVG has an explicit width, it uses that width, within the boundaries of those extremes. But unfortunately it also means if the SVG _doesn't_ have an explicit width or height, it collapses to the min-width and min-height. This PR updates documentation, and adds explicit dimensions for all block icons used. Before:  After: 
|
|
||
| return icon(); | ||
| } else if ( icon && icon.type === 'svg' ) { | ||
| } else if ( isSVGIcon( icon ) ) { |
There was a problem hiding this comment.
I wanted to write this way simpler, like this:
} else if ( icon && icon.type === 'svg' || icon && icon.type.name === 'SVG' ) {
const appliedProps = {
...icon.props,
width: icon.props.width || 24,
height: icon.props.height || 24,
};
return <SVG { ...appliedProps } />;
}
But for whatever reason, this did not pass linting tests. I'm not sure why, as this implementation seems far more complex.
| function isSVGIcon( icon ) { | ||
| if ( icon && icon.type === 'svg' ) { | ||
| return true; | ||
| } else if ( icon && icon.type.name === 'SVG' ) { |
There was a problem hiding this comment.
You can check also refactor it as:
return icon && ( icon.type === 'svg' || icon.type === SVG );There was a problem hiding this comment.
You mean
return icon && ( icon.type === 'svg' || icon.type.name === SVG );
right?
If so, YAY, that's what I wanted! Thank you. Will update.
There was a problem hiding this comment.
Oh really, will that work? Let me give it a shot! Thanks again.
There was a problem hiding this comment.
it's the same thing as with <svg - type is the name of the component that was used to create an actual element - in first case it's svg (string for html tag has special handling), in the second it's the SVG component.
There was a problem hiding this comment.
Okay, pushed 1f4a19b — is that kosher? I don't like creating an entirely new function if we don't have to.
|
🚢 |
* Fix icon size regression. This is an alternative to WordPress#10938 which for whatever reason I can't rebase. The purpose is the same: This PR fixes an icon size regression that was introduced in WordPress#9828. Basically SVG icons are _between 20 and 24px_. If an SVG has an explicit width, it uses that width, within the boundaries of those extremes. But unfortunately it also means if the SVG _doesn't_ have an explicit width or height, it collapses to the min-width and min-height. This PR updates documentation, and adds explicit dimensions for all block icons used. Before:  After:  * Pretty up the code a bit.

This is an alternative to #10938 which for whatever reason I can't rebase. The purpose is the same:
This PR fixes an icon size regression that was introduced in #9828. Basically SVG icons are between 20 and 24px.
If an SVG has an explicit width, it uses that width, within the boundaries of those extremes. But unfortunately it also means if the SVG doesn't have an explicit width or height, it collapses to the min-width and min-height.
This PR updates documentation, and adds explicit dimensions for all block icons used.
Before:
After: