Skip to content
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

Merged
merged 3 commits into from
Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions packages/block-editor/src/components/block-styles/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useState, useLayoutEffect } from '@wordpress/element';
import { useViewportMatch } from '@wordpress/compose';
import {
Button,
__experimentalText as Text,
__experimentalTruncate as Truncate,
Slot,
Fill,
} from '@wordpress/components';
Expand Down Expand Up @@ -117,15 +117,12 @@ function BlockStyles( {
onClick={ () => onSelectStylePreview( style ) }
aria-current={ activeStyle.name === style.name }
>
<Text
as="span"
limit={ 12 }
ellipsizeMode="tail"
<Truncate
numberOfLines={ 1 }
className="block-editor-block-styles__item-text"
truncate
>
{ buttonText }
</Text>
</Truncate>
</Button>
);
} ) }
Expand Down
10 changes: 10 additions & 0 deletions packages/block-editor/src/components/block-styles/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@
box-shadow: inset 0 0 0 1px $white, 0 0 0 2px var(--wp-admin-theme-color);
}
}

.block-editor-block-styles__item-text {
word-break: break-all;
// 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;
}
}

// To prevent overflow in the preview container,
Expand Down