-
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
Block Styles: Truncate long button labels #42975
Conversation
Text → Truncate
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 contributing!
I see that the ellipsis isn't being shown. This is because the Button component has white-space: nowrap
. We need to add a few more styles for this to look good (please keep the code comments, since they are non-obvious 🙂):
.block-editor-block-styles__item-text {
// The Button component is white-space: nowrap, and that won't work with line-clamp.
white-space: normal;
// Without this, the ellipsis can sometimes be partially hidden by the Button padding.
text-align: start;
text-align-last: center;
}
The text-align is an interesting one. Notice how the ellipsis can get partially hidden without the special handling:
Before | After |
---|---|
(cc @ciampo for awareness. We might want to bake this into the components library if we encounter this again.)
@mirka I was able to confirm that the ellipsis is displayed in long CJK characters after applying the suggested CSS. However, the ellipsis is no longer displayed for long English words. |
@@ -43,6 +43,16 @@ | |||
display: inline-block; | |||
width: calc(50% - #{$grid-unit-05}); | |||
|
|||
&-text { |
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.
Nit: I'd prefer this to be written out (.block-editor-block-styles__item-text
) so it can be searched easily across the codebase.
Also, no need to nest it this deep since the class will never appear anywhere else, and it just adds unnecessary specificity.
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.
@mirka
Thanks for the review.
I've adjusted the .block-editor-block-styles__item-text
class to make it easier to isolate and search.
How about something like this?
@@ -43,6 +43,16 @@ | |||
display: inline-block; | |||
width: calc(50% - #{$grid-unit-05}); | |||
|
|||
&-text { | |||
word-break: break-all; |
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.
Great catch, I looked into this a little further and it's pretty interesting. This might be something we need to bake into Truncate. Maybe word-break: break-all
when numberOfLines
is 1, and overflow-wrap: break-word
when it's multiple lines. I'll keep track of this as a separate issue.
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, thanks for the solid i18n improvement! 🚀
* fix blockType Text Text → Truncate * Block Styles css * Block Styles css
Cherry-picked for WordPress 6.0.2 release with 693a7ac. |
Resolves #40463
Related #40807 #41455
What?
Changed character limit to be calculated from character width.
Why?
How?
#40463 (comment) is used to calculate the width of the character count using the string-width package.
#40463 (comment)
Before
After
Testing Instructions
Go to the block editor and place the image block.
Open the side panel and look at the style preview.
Screenshots or screencast