-
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
ToolbarButton: Fix text centering for short labels #59117
Conversation
12dba7b
to
4d459cc
Compare
Size Change: +10 B (0%) Total Size: 1.7 MB
ℹ️ View Unchanged
|
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. |
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 fix here @talldan 👍
This PR centres the toolbar buttons for me as advertised.
Within the code I could also see a range of ToolbarItem
components with the as="Button"
prop but I didn't see any of these misaligned in the editor.
When the "show button text labels" preference is enabled the buttons were still centred correctly as well.
LGTM 🚢
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.
Seems like a good addition! Not sure about the impact of other parts of the editor though. Given that it's a pretty small diff we can always revert it when necessary. 👍
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 checked whether this should be addressed in the Button component itself, but it's irrelevant there because there is no min-width set unless it's an icon button.
One thing that may be worth considering is to collocate the justify-content: center
declaration closer to where the problem is introduced, rather than in the toolbar-button
stylesheet where the problem is unlikely to manifest in isolation. That would make it less likely for someone in the future to prune that rule by accident. No strong opinion on this if it poses other complications though.
4d459cc
to
8acb599
Compare
Good suggestion - I've done that. |
What?
Observed here - #58998 (review)
When a toolbar button has a short string, the min width css rule can come into action (the button is no longer assuming the size of its content. When that happens it's noticeable that there's no center alignment of the button content.
This PR adds a
justify-content: center;
rule so that content is always centeredNote
There seem to be a whole bunch of styles for toolbar button that use the
.components-toolbar__control.components-button
class name. Most toolbar buttons use onlycomponents-toolbar-button
now. The former class name seems to be used when the toolbar has an 'inaccessible' state (which is triggered when a toolbar contains something like a regularButton
). The potential for drift between these styles might be a little bit of a worry. When I tested, thejustify-content
rule wasn't needed for this style of button.There are also some places in the codebase where
components-toolbar__control
is manually added, which is quite anti-BEM.Testing Instructions
Screenshots or screencast
Before
After