Skip to content

Block Styles button labels are truncated #40331

Closed

Description

@erickyle

Description

The block style button label is constrained to a small number of characters. Hovering over the block style button does reveal a preview with the full name, but this forces the user to hover over each of the block style buttons to reveal the full name. The built-in blocks and block styles tend to use single-word, short labels, so the issue may not be readily apparent with a stock configuration.

image

It may be better to present the block style buttons as a single column with a much larger number of characters supported, versus the two-column button layout that is currently in use. Note that the screen capture below uses a a transparent variant of the --wp-admin-theme-color--rgb CSS custom property.

image

This issue is related to #37039

Step-by-step reproduction instructions

  1. Insert a block that has block styles with long names associated with it.
  2. Inspect the block styles in the settings panel.

Screenshots, screen recording, code snippet

No response

Environment info

  • WordPress 6.0-beta1-53168
  • Twenty Twenty-Two theme active
  • WordPress Beta Tester is the only plugin installed
  • Gutenberg plugin is not installed

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

Activity

  1. jasmussen commented on Apr 14, 2022

    @jasmussen
    Contributor

    Good ticket, thank you, I'll be curious to hear what others think as well. I personally like that the button size encourages short and concise labels, and that the overall footprint of the style interface is balanced against design tools below, making the interface a set of complementary shortcuts rather than the primary block interface.

    I wonder if there's a way to automatically adjust the interface size, such as if more than n styles are detected, it becomes a full-width dropdown? 🤔

  2. erickyle commented on Apr 14, 2022

    @erickyle
    Author

    Glad to help. I would be fine with leaving it as-is if there was a way to override the truncation easily. I wonder instead of truncating the string before output, if it would not be better to truncate it after output using CSS.
    https://css-tricks.com/snippets/css/truncate-string-with-ellipsis/

  3. mrwweb commented on Jul 20, 2022

    @mrwweb

    I'll be curious to hear what others think as well. I personally like that the button size encourages short and concise labels

    I do not like it and find that it's hard to write descriptive enough labels in the available space. I wouldn't say "encourage" but rather "enforce." I honestly think it should just be reverted to show the whole label, but some kind of override would be acceptable. If there is a huge concern about the space it takes up, using a select menu or a scrollable container would be an improvement over the current implementation (though a scrollable container would have its own downsides).

    Since this is a developer opt-in feature, it feels like it should be left to the developer to make this decision. I agree that shorter labels are better, but the available space really short.

    I spend a lot of time and through trying to write short labels and I can't even come close to fitting in the available space at least half the time. Here are some recent examples of styles that I don't think I could shorten any further that are truncated:

    • Circle Gradient: Brick to Blue ("Circle Gradi…")
    • Circle Gradient: Yellow to Teal ("Circle Gradi…")
    • Not Stretched ("Not Stretche..." - In this case the ellipsis truncates the word when it wouldn't have to without it!)
    • Centered Not Stretched ("Centered Not…")
    • Small Grayscale Logos ("Small Graysc…")
    • Snug to Heading ("Snug to Head…")
    • space-around Alignment ("space-around..." - See Add space-around justification option to Buttons Block #42536)

    Especially since it's not possible to combine Block Styles (#14598), it's more likely to need longer, composite names like the "Small Grayscale Logos" or Circle Gradient variation styles above.

    Further, it's possible that the tooltip avoids a formal accessibility failure, but I think most of the logic in a few recent articles still applies.

    From "The Ballad of Text Overflow":

    If text has been truncated with text-overflow, then this is a loss of content, and therefore an instant failure of 1.4.10.

    See also: ["Text Overflow: Ellipsis Considered Harmful"](Text-overflow: ellipsis considered harmful).

  4. jasmussen commented on Aug 13, 2026

    @jasmussen
    Contributor

    Thanks for the feedback, all valid, and agree truncation is a bit inelegant and has an opportunity cost in this case.

    Just to unblock things, here's a quick and dirty truncation-removal test:

    Image

    Of course I'm not serious about the above, but it does reveal some questions that are worth answering, such as: is Button still the right component to use for these, or should it be something else? And, are there any grid based properties that allow us to have two columns if the labels are short but have 1 column if the labels are long and need to wrap? The main motivation is that for a lot of basic themes, including the default Twenty themes, you'll likely see simple labels like these:

    Image

    The downside of simply enforcing 1 column across all labels, is that the above panel would take up double the vertical space without absolutely having to, and as a result pushing valuable controls like Typography and Colour downwards.

    So I'd love to pass a question on to @WordPress/gutenberg-components: can we have the cake, and eat it too? No wrapping, and 2 columns if labels are short, 1 column if labels are long? That could also be a fun intrinsic webdesign challenge for anyone reading. The motivation is primarily to seek the simplest possible solution that works for as many contexts as possible. Is that fair?

  5. added
    Needs DevReady for, and needs developer efforts
    and removed on Aug 13, 2026
  6. mirka commented on Aug 13, 2026

    @mirka
    Member

    The motivation is primarily to seek the simplest possible solution that works for as many contexts as possible.

    My first instinct would be a select, rather than a bunch of buttons. I think the wp-ui version would allow for the preview cards as well.

  7. ciampo commented on Aug 17, 2026

    @ciampo
    Contributor

    Agreed with Lena — select feels like the natural choice here, especially since we don't have any "radio cards" components yet.

  8. t-hamano commented on Aug 18, 2026

    @t-hamano
    Contributor

    I think the wp-ui version would allow for the preview cards as well.

    I did a little testing. Is this how it looks? @jasmussen What do you think?

    block-styles.mp4
  9. 7 remaining items

  10. jasmussen commented on Aug 19, 2026

    @jasmussen
    Contributor

    I also think the quick and dirty truncation removal is pretty good, especially if you could keep it to only two lines instead of one?

    Buttons-system-wise, is there a clean and nice way to do this?

  11. ciampo commented on Aug 19, 2026

    @ciampo
    Contributor

    To make sure I'm following here, the latest proposal is to:

    • Keep two columns when labels fit comfortably.
    • Let an individual option occupy the full row when it needs more width.
    • Clamp button labels on one line (or two at most). Truncate when they overflow

    I also think the quick and dirty truncation removal is pretty good, especially if you could keep it to only two lines instead of one?

    Buttons-system-wise, is there a clean and nice way to do this?

    The @wordpress/ui Button allows its content to break to multiple lines, but:

    Image

    Here are my thoughts:

    • We should reduce truncation as much as possible. Allowing labels to wrap to two lines and buttons to occupy a full row would both be improvements.
    • A dynamic layout isn't completely out of the question, but we need to define its behavior precisely before deciding whether it is simple to implement. A few questions that come to mind:
      • How do we determine that a label needs a full row? It should depend on rendered width and it will need to respond to various external factors (eg translations, fonts, zoom, sidebar width...). If we end up needing to measure with JS, it may be complex and runtime expensive.
      • If a short label is followed by a long one, does the long button move to a full-width row? If so, does the short button remain alone at half width? Or expand to full width to fill the empty gap?
      • What happens to an odd final button? Does it remain half-width or expand?
      • Should buttons in the same row always have equal heights? (relevant if we allow button labels to wrap on 2 lines)
    • CSS intrinsic sizing may be able to handle some of this without JavaScript measurement. However, CSS still needs deterministic layout rules; it cannot answer the design questions above for us.
    • The semantics on this widget should also be reconsidered, potentially making it a radio group (visually styled as buttons)

    My concern is that we risk overcomplicating this feature.

  12. jasmussen commented on Aug 19, 2026

    @jasmussen
    Contributor

    Thanks for your deep response, much appreciated.

    To make sure I'm following here

    To clarify specifically what I meant, I meant keep everything as it exists today, but simply allow the buttons to wrap the text inside, like this but ideally nicer:

    Image

    It may not work, but if it does, it keeps one-click style changes, affords more verbose labels, and only pushes content in the sidebar down in the cases where you have a LOT of styles, in which case that might be desired after all.

    The main reason this could not work is if the grid of buttons ends up entirely lopsided, with some buttons taller than others. That's probably the main challenge.

  13. ciampo commented on Aug 19, 2026

    @ciampo
    Contributor

    Right! Yes, some buttons will be taller than others. We can mitigate by making sure that buttons in the same row have the same height? Would that be enough?

  14. jasmussen commented on Aug 19, 2026

    @jasmussen
    Contributor

    If it's relatively trivial to try, it might be, yes.

    The thing is: it would possibly address this issue, but it would also leave it up to theme-developers to editorially balance their style titles. I.e. with no risk of truncation, they could carefully tailor their titles to have all 1 or 2 or 3 lines of text, or be fine with differeing sizes.

  15. ciampo commented on Aug 19, 2026

    @ciampo
    Contributor

    Allowing up to 2 lines of text and then truncating would be the better compromise?

  16. jasmussen commented on Aug 19, 2026

    @jasmussen
    Contributor

    None of my opinions are strong, and I defer to any others on this thread chiming in.

    But I wouldn't truncate anything at all, and leave it completely to the theme-developer to editorially decide. If a followup issue materialises that shows a 10-line style button, I guess that's when we know the dropdown is the answer. Is that fair?

  17. ciampo commented on Aug 19, 2026

    @ciampo
    Contributor

    Sounds good to me for a couple of reasons:

    • we potentially avoid truncation (and tooltip) altogether, which is great
    • we start simple, and can always revisit later if necessary.

    The risks to monitor are:

    • extemely long labels that look weird
    • consumers implementing their own truncation in a non-accessible way (ie. without correct accessible label and tooltips)
  18. t-hamano commented on Aug 19, 2026

    @t-hamano
    Contributor

    Allowing up to 2 lines of text and then truncating would be the better compromise?

    I tested this. The code changes are very simple.

    https://github.com/WordPress/gutenberg/compare/update/block-styles-ui-button?expand=1

    Code to add block style variations for the Paragraph block from the browser console
    ( () => {
    	const BLOCK = 'core/paragraph';
    
    	// The order is fixed, not shuffled, so that each grid row pairs labels of a
    	// known length. `getRenderedStyles` prepends a "Default" style because none
    	// of these is the default, so "Default" fills the first cell of row 1 and
    	// every pair below lands on its own row.
    	const styles = [
    		// Row 1 (with "Default"): both fit on one line — the shortest row.
    		{ name: 'test-1char', label: 'A' },
    
    		// Row 2: a one-line label next to a two-line one, so the short button
    		// is stretched to the height of its row.
    		{ name: 'test-short', label: 'Bold' },
    		{ name: 'test-two-lines', label: 'Large drop cap with serif type' },
    
    		// Row 3: back to one line, so the height drops again between rows.
    		{ name: 'test-short-2', label: 'Plain' },
    		{ name: 'test-ja-short', label: '本文' },
    
    		// Row 4: both run past two lines and end in an ellipsis.
    		{
    			name: 'test-long',
    			label: 'Subtle background with rounded corners',
    		},
    		{
    			name: 'test-very-long',
    			label: 'Extra emphasised introduction paragraph for long form articles',
    		},
    
    		// Row 5: unbreakable words — they must wrap mid-word rather than widen
    		// the column, which is what `overflow-wrap: anywhere` and
    		// `minmax(0, 1fr)` are there for.
    		{
    			name: 'test-unbreakable',
    			label: 'Donaudampfschifffahrtsgesellschaftskapitaenswitwe',
    		},
    		{
    			name: 'test-url',
    			label: 'https://example.com/very/long/path/to/a/block/style',
    		},
    
    		// Row 6: CJK line breaking and truncation.
    		{
    			name: 'test-ja-long',
    			label: '長いラベルを持つ日本語のブロックスタイルバリエーション見本',
    		},
    		{ name: 'test-ja-short-2', label: '太字' },
    	];
    
    	wp.blocks.registerBlockStyle( BLOCK, styles );
    
    	window.unregisterTestBlockStyles = () => {
    		styles.forEach( ( { name } ) =>
    			wp.blocks.unregisterBlockStyle( BLOCK, name )
    		);
    		delete window.unregisterTestBlockStyles;
    	};
    
    	console.log(
    		`Registered ${ styles.length } styles on ${ BLOCK }. Run unregisterTestBlockStyles() to remove them.`
    	);
    } )();
    Before After
    Image Image
    Image Image

    The key point is that the button height changes depending on the row, but personally, I find this acceptable.

  19. jasmussen commented on Aug 19, 2026

    @jasmussen
    Contributor

    Does it start to look very poor with 3 lines? If it isn't terrible, and depending on any others chiming in, it could be key.

  20. t-hamano commented on Aug 19, 2026

    @t-hamano
    Contributor

    Does it start to look very poor with 3 lines?

    I tried this. #81833 The PR also includes accessibility improvements.

  21. jasmussen commented on Aug 20, 2026

    @jasmussen
    Contributor

    I tried this. #81833 The PR also includes accessibility improvements.

    Thanks for trying that. Your examples are extreme (which is good!) with a simple "A" term on the left, and a three line row on the right. It does look a bit lopsided there.

    However, it's still the simplest possible solution, and it notably bends to the will of the theme developer and what they desire to do editorially: able to choose all in one line each, or two, or three lines. Mixing is possible too.

    Because it is the simplest solution that fixes this issue, and absent anyone from this issue chiming in, I would be in favour of trying this as the first step.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions