-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Fix icon size regression in Switcher #13767
Conversation
Would it be possible to check if the second child is an SVG element, and if so, not add the |
@@ -23,7 +23,7 @@ class IconButton extends Component { | |||
const { icon, children, label, className, tooltip, shortcut, labelPosition, ...additionalProps } = this.props; | |||
const { 'aria-pressed': ariaPressed } = this.props; | |||
const classes = classnames( 'components-icon-button', className, { | |||
'has-text': children, | |||
'has-text': children && children.length > 2, |
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.
children
is an opaque object type, and length
is not intended to be reliable.
See also: https://reactjs.org/docs/react-api.html#reactchildren
Specifically: https://reactjs.org/docs/react-api.html#reactchildrencount
import { Children } from '@wordpress/element';
// ...
'has-text': Children.count( children ) > 2
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.
Thanks for the code improvement suggestion, much appreciated. Though counting the children to be more than 2 on its own feels hacky — do you have any suggestions for how to make sure that the "has-text" returns true when the IconButton has [Icon] Label
, but false in cases of [Icon] [Icon]
in a more reliable way?
As I see it, In other words, I think if we change this: gutenberg/packages/editor/src/components/block-switcher/index.js Lines 111 to 123 in 1c583b2
...to something more like: <IconButton
{ /* ... */ }
icon={ (
<Fragment>
<BlockIcon />
<SVG />
</Fragment>
) }
/> ...then we no longer need to deal with the problem of trying to figure out what sort of |
In #12901, a small margin was introduced to the IconButton component when text was present. This caused an issue with block icons, scaling them down when they shouldn't be. A 20x20px icon should show as 20x20, and a 24x24px icon should show as 24x24px. The additional margin was applied even when the IconButton didn't actually have text. It simply needed `children`, and in the case of the Switcher, it has a dropdown arrow. Combined with the fixed width of the switcher, that meant a 24x24 icon would be rendered as 20x24. This PR adds a length check so if your IconButton includes more than 2 letters, it's considered to have a text label. This fixes the issue. But as you can tell, maybe it's not the best way to check whether there's text or not. Suggestions most welcome.
Props @aduth for essentially writing this PR.
50a2e72
to
773bc4e
Compare
Note to self: If we can consider an May not be worth the effort, depending on #7534 (comment). |
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.
The previous build failed, but it looked to be an intermittent end-to-end test failure. I've restarted it.
Code-wise LGTM 👍 (I may be biased 😄 )
The idea is to have two icons combined so this proposal makes sense 👍 |
* Fix icon size regression in Switcher In #12901, a small margin was introduced to the IconButton component when text was present. This caused an issue with block icons, scaling them down when they shouldn't be. A 20x20px icon should show as 20x20, and a 24x24px icon should show as 24x24px. The additional margin was applied even when the IconButton didn't actually have text. It simply needed `children`, and in the case of the Switcher, it has a dropdown arrow. Combined with the fixed width of the switcher, that meant a 24x24 icon would be rendered as 20x24. This PR adds a length check so if your IconButton includes more than 2 letters, it's considered to have a text label. This fixes the issue. But as you can tell, maybe it's not the best way to check whether there's text or not. Suggestions most welcome. * Address feedback. Props @aduth for essentially writing this PR.
* Fix icon size regression in Switcher In #12901, a small margin was introduced to the IconButton component when text was present. This caused an issue with block icons, scaling them down when they shouldn't be. A 20x20px icon should show as 20x20, and a 24x24px icon should show as 24x24px. The additional margin was applied even when the IconButton didn't actually have text. It simply needed `children`, and in the case of the Switcher, it has a dropdown arrow. Combined with the fixed width of the switcher, that meant a 24x24 icon would be rendered as 20x24. This PR adds a length check so if your IconButton includes more than 2 letters, it's considered to have a text label. This fixes the issue. But as you can tell, maybe it's not the best way to check whether there's text or not. Suggestions most welcome. * Address feedback. Props @aduth for essentially writing this PR.
In #12901, a small margin was introduced to the IconButton component when text was present. This caused an issue with block icons, scaling them down when they shouldn't be. A 20x20px icon should show as 20x20, and a 24x24px icon should show as 24x24px.
The additional margin was applied even when the IconButton didn't actually have text. It simply needed
children
, and in the case of the Switcher, it has a dropdown arrow. Combined with the fixed width of the switcher, that meant a 24x24 icon would be rendered as 20x24.This PR adds a length check so if your IconButton includes more than 2 letters, it's considered to have a text label. This fixes the issue. But as you can tell, maybe it's not the best way to check whether there's text or not. Suggestions most welcome.
Before:
After:
A good way to test this is to insert an Image placeholder block. The "Upload" button is actually an IconButton, so it should have margin, whereas the Switcher should not.