Skip to content

Add space-around and space-evenly justification options - #71129

Open
Sukhendu2002 wants to merge 20 commits into
WordPress:trunkfrom
Sukhendu2002:add/buttons-block-space-justification-options
Open

Sukhendu2002 wants to merge 20 commits into
WordPress:trunkfrom
Sukhendu2002:add/buttons-block-space-justification-options

Conversation

@Sukhendu2002

@Sukhendu2002 Sukhendu2002 commented Aug 8, 2025 •

Copy link
Copy Markdown
Contributor

What?

Closes: #42536

This PR adds support for space-around and space-evenly CSS flexbox justify-content values to the Buttons block.

Why?

Currently, the Buttons block only supports basic justification options (left, center, right, space-between). Adding space-around and space-evenly gives users more precise control over button spacing and alignment, especially useful for creating balanced layouts with multiple buttons.

Testing Instructions

  1. Insert a Buttons block
  2. Add multiple button items
  3. Switch to horizontal orientation
  4. Test all 6 justification options:
    • Left, Center, Right (existing)
    • Space Between (existing)
    • Space Around (new)
    • Space Evenly (new)
  5. Verify proper spacing behavior for each option

Screenshots or screencast

Screenshot 2025-08-08 at 2 57 21 PM

@im3dabasia im3dabasia added [Type] Enhancement A suggestion for improvement. [Block] Buttons Affects the Buttons Block labels Aug 8, 2025
@Sukhendu2002
Sukhendu2002 marked this pull request as ready for review August 8, 2025 13:01
@t-hamano t-hamano added the [Feature] Layout Layout block support, its UI controls, and style output. label Aug 19, 2025
@getsource getsource added the Needs Design Feedback Needs general design feedback. label Aug 26, 2025
@jasmussen

Copy link
Copy Markdown
Contributor

Nice PR, this seems valid to me, and I can potentially help with some icons. Before we go about that, I'd love broader input, @WordPress/gutenberg-design what do you think about these options?

@henriqueiamarino

Copy link
Copy Markdown

I’m echoing @jasmussen, @Sukhendu2002; for me, this is quite valid. However, within the themesdesign channel, we concluded that while space-evenly makes sense, space-around can already be achieved with regular justification and side padding, so it's not strictly necessary.

@t-hamano

t-hamano commented Mar 6, 2026

Copy link
Copy Markdown
Contributor

I think space-evenly is definitely useful. cc @tellthemachines @andrewserong

@andrewserong

Copy link
Copy Markdown
Contributor

I think space-evenly is definitely useful.

Same here. I think the only real concern I'd have is how dense the justification controls might feel, but adding one more sounds reasonable to me.

If adding it to the flex layout, comparable changes will also need to be added to some PHP files for layout and navigation, I believe:

E.g:

$layout_justification = array(
'left' => 'items-justified-left',
'right' => 'items-justified-right',
'center' => 'items-justified-center',
'space-between' => 'items-justified-space-between',
);

And:

if ( 'horizontal' === $layout_orientation ) {
$justify_content_options += array( 'space-between' => 'space-between' );
$vertical_alignment_options += array( 'stretch' => 'stretch' );
} else {
$justify_content_options += array( 'stretch' => 'stretch' );
$vertical_alignment_options += array( 'space-between' => 'space-between' );
}

@jasmussen

Copy link
Copy Markdown
Contributor

Same here. I think the only real concern I'd have is how dense the justification controls might feel, but adding one more sounds reasonable to me.

Oh indeed, there's this control:

image

They would fit fine in this dropdown:

image

I wanted to try and see if that aligned in the inspector, but it didn't come together for me:

Frame 2

For that reason, I think this one needs a little design work. Let me put it on my laundry list and see if I can come up with something. Thanks all!

@jasmussen

Copy link
Copy Markdown
Contributor

Apologies for the delay, long days. I found some time and shared some designs in #42536 (comment).

@t-hamano

Copy link
Copy Markdown
Contributor

Hi @Sukhendu2002, do you have the bandwidth to work on this PR? In addition to resolving code conflicts, we need to address the following tasks:

@Sukhendu2002
Sukhendu2002 force-pushed the add/buttons-block-space-justification-options branch from 85817e8 to e6ef0e0 Compare September 24, 2026 05:48
@github-actions github-actions Bot added [Package] Block editor /packages/block-editor [Package] Icons /packages/icons labels Sep 24, 2026
@Sukhendu2002
Sukhendu2002 force-pushed the add/buttons-block-space-justification-options branch 2 times, most recently from f1f4636 to e13d9a9 Compare September 24, 2026 09:46
@github-actions github-actions Bot added the [Package] Block library /packages/block-library label Sep 24, 2026
Sukhendu2002 added a commit to Sukhendu2002/gutenberg that referenced this pull request Sep 24, 2026
@Sukhendu2002

Copy link
Copy Markdown
Contributor Author

Thanks @t-hamano! Conflicts are resolved, the panel design and PHP/Navigation support are updated, and tests were added. Trac: https://core.trac.wordpress.org/ticket/66172. Core backport: WordPress/wordpress-develop#13710. Ready for re-review.

@t-hamano t-hamano left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update! However, I think there are still a few areas that need to be updated.

- `is-content-justification-left`: When a block explicitly sets `justifyContent` to `left`.
- `is-content-justification-center`: When a block explicitly sets `justifyContent` to `center`.
- `is-content-justification-right`: When a block explicitly sets `justifyContent` to `right`.
- `is-content-justification-space-between`: When a block explicitly sets `justifyContent` to `space-between`.

&:not(
.is-content-justification-space-between,
.is-content-justification-right,
.is-content-justification-left,
.is-content-justification-center
) .wp-block[data-align="center"] {

&:not(
.is-content-justification-space-between,
.is-content-justification-right,
.is-content-justification-left,
.is-content-justification-center
) .wp-block-button.aligncenter {

&.is-content-justification-space-between {
justify-content: space-between;
}

**NOTE:** The justify toolbar does not add any classes to your component, you must do this using the `setAttributes` function. The toolbar does define the following classnames you should use:
items-justified-left
items-justified-center
items-justified-right
items-justified-space-between

A callback function invoked when the toolbar's justification value is changed via an interaction with any of the toolbar's buttons. Called with the new alignment value (ie: `left`, `center`, `right`, `space-between`, `undefined`) as the only argument.

.items-justified-space-between {
justify-content: space-between;
}

Additionally, we also need to consider whether we should change the default control for JustifyContentControl.

function JustifyContentUI( {
allowedControls = [ 'left', 'center', 'right', 'space-between' ],

@Sukhendu2002
Sukhendu2002 force-pushed the add/buttons-block-space-justification-options branch from a2c3aa0 to 88ccb1d Compare September 25, 2026 13:37
@github-actions github-actions Bot removed the [Package] Icons /packages/icons label Sep 25, 2026

@t-hamano t-hamano left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update! I think it's almost complete, but I found a few more areas that need updating.

.wp-block-navigation {
// space-between justification.
&.items-justified-space-between {

// When justified space-between, open submenus leftward for last menu item.
// When justified right, open all submenus leftwards.
// This needs high specificity.
.wp-block-navigation.items-justified-space-between .wp-block-page-list > .has-child:last-child,
.wp-block-navigation.items-justified-space-between > .wp-block-navigation__container > .has-child:last-child,
.wp-block-navigation.items-justified-right .wp-block-page-list > .has-child,
.wp-block-navigation.items-justified-right .wp-block-navigation__container .has-child {

"enum": [
"right",
"center",
"space-between",
"left",
"stretch"
]

Comment thread packages/block-library/CHANGELOG.md Resolved
Comment thread packages/block-editor/CHANGELOG.md Resolved
@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

🎉 Props

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: Sukhendu2002 <sukhendu2002@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: jasmussen <joen@git.wordpress.org>
Co-authored-by: henriqueiamarino <iamarinoh@git.wordpress.org>
Co-authored-by: andrewserong <andrewserong@git.wordpress.org>
Co-authored-by: jameskoster <jameskoster@git.wordpress.org>
Co-authored-by: fcoveram <fcoveram@git.wordpress.org>
Co-authored-by: ciampo <mciampini@git.wordpress.org>
Co-authored-by: tellthemachines <isabel_brison@git.wordpress.org>
Co-authored-by: mrwweb <mrwweb@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

@Sukhendu2002
Sukhendu2002 requested a review from t-hamano October 14, 2026 16:48

@t-hamano t-hamano left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Sukhendu2002 Thanks for the update!

The current UI doesn't have an icon, but in my opinion, it should have one.

Image

@WordPress/gutenberg-design, here are a few potential variations—which one do you think is best? Personally, I think displaying the label, description, and icon together would be the clearest.

Image

@jameskoster

Copy link
Copy Markdown
Contributor

Agree on showing the icon. The descriptions I'm less sure about. They add a lot of weight and kind of repeat the label in more words—I'm uncertain how helpful they are as an addition. At a push, including them for the less obvious options might work, but I'm unconvinced. Not a strong opinion though; if y'all think they're helpful then I don't object.

It might be nice to show the icon in the trigger too.

@fcoveram

Copy link
Copy Markdown
Contributor

Agree with Jay, the description adds too much information

@jasmussen

Copy link
Copy Markdown
Contributor

Can we start without the descriptions to land this PR, see if it floats, and then ponder whether we add the descriptions back as a followup?

@t-hamano

Copy link
Copy Markdown
Contributor

@Sukhendu2002, can you resolve the conflicts and try using the icon + label pattern (without the description)?

@t-hamano t-hamano left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update! From a code perspective, I think this PR is complete, but from a design standpoint, there still seems to be room for discussion.

It might be nice to show the icon in the trigger too.

Personally, I prefer removing the icons from the trigger because the full text might not be displayed, making it hard to read.

Image

If we remove the icon, we should be able to restore this gap—which was narrowed to 4px—back to 16px. In other words, it will look like this:

Image

Another approach might be to stop placing Justification and Orientation side by side. Either way, I look forward to hearing your ideas.

@t-hamano t-hamano left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Sukhendu2002 Thanks for the update! As far as I can tell, this PR looks ready to ship. @tellthemachines @andrewserong @jasmussen, could you take another look?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I don't think this test is necessary. It only asserts that the labels of the default allowedControls array are rendered in order, which essentially mirrors a constant.

value={ selectedOption }
isItemEqualToValue={ ( item, value ) => item.value === value.value }
onValueChange={ ( selectedItem ) => {
if ( selectedItem && selectedItem.value !== null ) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if ( selectedItem && selectedItem.value !== null ) {
if ( selectedItem ) {

Nit: The value of each option is always a string, so the null check isn't needed.

@jasmussen

Copy link
Copy Markdown
Contributor

I'm happy to try this. Agree on not showing the icon at rest so we have more room for text. And just at a quick glance, the gap between toggles and select here, looks a bit tight:

image

Presumably there's a systematised gap value we can reuse here.

This branch has not been deployed

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

Labels

[Block] Buttons Affects the Buttons Block [Feature] Layout Layout block support, its UI controls, and style output. Needs Design Feedback Needs general design feedback. [Package] Block editor /packages/block-editor [Package] Block library /packages/block-library [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add space-around justification option to Buttons Block

9 participants