-
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
Button: Remove unnecessary margin from dashicon #51395
Conversation
Size Change: -30 B (0%) Total Size: 1.4 MB
ℹ️ View Unchanged
|
Flaky tests detected in bbd89ed. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5297188139
|
a8da456
to
833c720
Compare
.dashicon { | ||
display: inline-block; | ||
flex: 0 0 auto; | ||
margin-left: 2px; | ||
margin-right: 2px; | ||
} |
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.
This left/right margin exists to widen the default size of the dash icon, 20px, to 24px.
As this comment suggests, I would ideally like to remove these margins as well, in order to solve the problem more upstream when the dashicon is used in the DropdownMenu
component, but so far I have not found a satisfactory approach.
One approach I thought of is to use padding instead of margin to widen the size and center the dashicon font of the pseudo-element inside.
.dashicon {
display: inline-flex;
justify-content: center;
align-items: center;
padding: 2px;
box-sizing: content-box;
}
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.
Yes, padding might be a little less fragile than margin.
5ef483e
to
8b3db8d
Compare
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.
Looks good! 🚀
I hope you don't mind that I push a local visual regression test to this PR. I can split it out to a separate PR if you prefer.
Vizreg results
We can see that the changes in this PR only affect Buttons where the text is specified via children
(not the text
prop), and also that the iconPosition
prop has no affect in this case 😅 so we're good.
Before
After
.dashicon { | ||
display: inline-block; | ||
flex: 0 0 auto; | ||
margin-left: 2px; | ||
margin-right: 2px; | ||
} |
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.
Yes, padding might be a little less fragile than margin.
8b3db8d
to
0b58a1b
Compare
Thanks for the review and for adding the visual regression test 🙏 I have added the approach suggested in this comment and performed a visleg test locally and got the same expected results. I would like to merge when all CIs have passed 👍 |
* Add vizreg test * Button: Remove unnecessary margin from dashicon * Update changelog * Revert some changes * Layout with padding instead of margin --------- Co-authored-by: Lena Morita <[email protected]>
What?
This PR removes the extra space that is added between the icon and the text when the dashicon is used in a
Button
component.Why?
In #50277, the gap is now used for spacing between icon and text. However, for dashicon,
margin-right
was still used for the spading between the icon and the text.How?
Removed unnecessary margin style. At the same time, I also removed unnecessary styles (
display: inline-block; flex: 0 0 auto;
) from the dashicon since it's a child of flex.Testing Instructions
Update the Edit component (
packages/block-library/src/code/edit.js
) of the code block as follows:Confirm that the width of the
Button
component with theIcon
component matches the width of theButton
compoent with the dashicon.Screenshots or screencast