Skip to content

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

Merged
t-hamano merged 33 commits into
WordPress:trunkfrom
Sukhendu2002:add/buttons-block-space-justification-options
Dec 3, 2026
Merged

t-hamano merged 33 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' ],

@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?

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I tried this, but it fails typecheck: onValueChange receives SelectItem from @wordpress/ui, whose value is typed string | null, so the check is needed to narrow it before calling onJustificationChange. I've kept it as is.

@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.

@github-actions
github-actions Bot requested review from aduth and ciampo November 30, 2026 07:02
@Sukhendu2002

Copy link
Copy Markdown
Contributor Author

Thanks! The gap between the Justification select and the Orientation toggles is currently gap={ 4 } (16px), the same value trunk uses for this row. Would you like me to bump it to a larger step, or does it look OK in the latest build? Happy to adjust.

@jasmussen

Copy link
Copy Markdown
Contributor

This one looks ready to merge. Should we land it, @WordPress/gutenberg-design ?

@ciampo ciampo 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.

This is close. I left one non-blocking note inline.

On the onValueChange null check: the current version is right. SelectItem.value is string | null, so if ( selectedItem ) alone fails typecheck. Also, selectedItem itself can be null at runtime, because Base UI resets the value when the option list changes. So that check is needed either way.

@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.

This could be handled as a follow-up, but we might want to refine the labels a bit more to improve consistency.

In the Stack layout, a single legacy Stretch item is mixed in among Left, Center, and Right. I think this should be Stretch.

image image

In the Constrained layout, the toolbar displays Left, Center, Right, but the inspector still uses the legacy labels. I think we should update the legacy labels to match the new ones.

image image

Comment thread backport-changelog/7.3/13710.md Resolved
@jasmussen

Copy link
Copy Markdown
Contributor

Agree on "Stretch" rather than "Stretch items"

@ciampo ciampo 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.

Almost there

@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! I've left two minor suggestions, but everything else looks good to me.

Comment thread packages/block-editor/CHANGELOG.md Resolved
@t-hamano
t-hamano merged commit a21d630 into WordPress:trunk Dec 3, 2026
84 checks passed
@github-actions github-actions Bot added this to the Gutenberg 24.7 milestone Dec 3, 2026
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

10 participants