From d06e41f512062e04d08de17d128528bbd32b2a1d Mon Sep 17 00:00:00 2001 From: Sukhendu Sekhar Guria Date: Fri, 8 Aug 2025 12:26:59 +0530 Subject: [PATCH 01/19] Add space-around and space-evenly justification --- .../justify-content-control/style.scss | 8 +++++ .../components/justify-content-control/ui.jsx | 18 ++++++++++ packages/block-editor/src/hooks/layout.scss | 11 ++++++ packages/block-editor/src/layouts/flex.jsx | 34 +++++++++++++++---- 4 files changed, 64 insertions(+), 7 deletions(-) diff --git a/packages/block-editor/src/components/justify-content-control/style.scss b/packages/block-editor/src/components/justify-content-control/style.scss index 79807378e13a7d..45eadcdaf73019 100644 --- a/packages/block-editor/src/components/justify-content-control/style.scss +++ b/packages/block-editor/src/components/justify-content-control/style.scss @@ -14,3 +14,11 @@ .items-justified-space-between { justify-content: space-between; } + +.items-justified-space-around { + justify-content: space-around; +} + +.items-justified-space-evenly { + justify-content: space-evenly; +} diff --git a/packages/block-editor/src/components/justify-content-control/ui.jsx b/packages/block-editor/src/components/justify-content-control/ui.jsx index 58c380eabc24e2..aaca9b60ffca2f 100644 --- a/packages/block-editor/src/components/justify-content-control/ui.jsx +++ b/packages/block-editor/src/components/justify-content-control/ui.jsx @@ -4,6 +4,8 @@ import { justifyCenter, justifyRight, justifySpaceBetween, + justifySpaceAround, + justifySpaceEvenly, justifyStretch, } from '@wordpress/icons'; import { __ } from '@wordpress/i18n'; @@ -13,6 +15,8 @@ const icons = { center: justifyCenter, right: justifyRight, 'space-between': justifySpaceBetween, + 'space-around': justifySpaceAround, + 'space-evenly': justifySpaceEvenly, stretch: justifyStretch, }; @@ -65,6 +69,20 @@ function JustifyContentUI( { isActive: 'space-between' === value, onClick: () => handleClick( 'space-between' ), }, + { + name: 'space-around', + icon: justifySpaceAround, + title: __( 'Space around items' ), + isActive: 'space-around' === value, + onClick: () => handleClick( 'space-around' ), + }, + { + name: 'space-evenly', + icon: justifySpaceEvenly, + title: __( 'Space evenly between items' ), + isActive: 'space-evenly' === value, + onClick: () => handleClick( 'space-evenly' ), + }, { name: 'stretch', icon: justifyStretch, diff --git a/packages/block-editor/src/hooks/layout.scss b/packages/block-editor/src/hooks/layout.scss index 8cfa9b57e8e4fb..51d8ec16ebc392 100644 --- a/packages/block-editor/src/hooks/layout.scss +++ b/packages/block-editor/src/hooks/layout.scss @@ -27,6 +27,17 @@ } } +.block-editor-hooks__flex-layout-justification-controls { + display: inline-flex; + flex-wrap: wrap; + max-width: 100%; + + .components-toggle-group-control { + flex-wrap: wrap; + max-width: 100%; + } +} + .block-editor-hooks__grid-layout-columns-and-rows-controls, .block-editor-hooks__grid-layout-minimum-width-control { // Reset `fieldset` browser defaults. diff --git a/packages/block-editor/src/layouts/flex.jsx b/packages/block-editor/src/layouts/flex.jsx index ac27c4e910c521..1e49773f9ea24b 100644 --- a/packages/block-editor/src/layouts/flex.jsx +++ b/packages/block-editor/src/layouts/flex.jsx @@ -4,6 +4,8 @@ import { justifyCenter, justifyRight, justifySpaceBetween, + justifySpaceAround, + justifySpaceEvenly, justifyStretch, justifyTop, justifyCenterVertical, @@ -37,6 +39,8 @@ const justifyContentMap = { right: 'flex-end', center: 'center', 'space-between': 'space-between', + 'space-around': 'space-around', + 'space-evenly': 'space-evenly', }; // Used with the vertical (column) flex orientation. @@ -494,7 +498,7 @@ function FlexLayoutJustifyContentControl( { }; const allowedControls = [ 'left', 'center', 'right' ]; if ( orientation === 'horizontal' ) { - allowedControls.push( 'space-between' ); + allowedControls.push( 'space-between', 'space-around', 'space-evenly' ); } else { allowedControls.push( 'stretch' ); } @@ -527,11 +531,23 @@ function FlexLayoutJustifyContentControl( { }, ]; if ( orientation === 'horizontal' ) { - justificationOptions.push( { - value: 'space-between', - icon: justifySpaceBetween, - label: __( 'Space between items' ), - } ); + justificationOptions.push( + { + value: 'space-between', + icon: justifySpaceBetween, + label: __( 'Space between items' ), + }, + { + value: 'space-around', + icon: justifySpaceAround, + label: __( 'Space around items' ), + }, + { + value: 'space-evenly', + icon: justifySpaceEvenly, + label: __( 'Space evenly between items' ), + } + ); } else { justificationOptions.push( { value: 'stretch', @@ -603,7 +619,11 @@ function OrientationControl( { layout, onChange } ) { if ( verticalAlignment === 'stretch' ) { newVerticalAlignment = 'top'; } - if ( justifyContent === 'space-between' ) { + if ( + justifyContent === 'space-between' || + justifyContent === 'space-around' || + justifyContent === 'space-evenly' + ) { newJustification = 'left'; } } From fb1e233107fc84dc9977c79197dcecfd6ad3f847 Mon Sep 17 00:00:00 2001 From: Sukhendu Sekhar Guria Date: Thu, 24 Sep 2026 11:42:06 +0530 Subject: [PATCH 02/19] feat(block-editor): update justification panel --- packages/block-editor/CHANGELOG.md | 4 + packages/block-editor/src/hooks/layout.scss | 16 ++-- packages/block-editor/src/layouts/flex.jsx | 79 +++++++++++++------ .../src/layouts/test/flex.jsdom.test.jsx | 2 +- 4 files changed, 71 insertions(+), 30 deletions(-) diff --git a/packages/block-editor/CHANGELOG.md b/packages/block-editor/CHANGELOG.md index f2e55279943339..7153d37776c298 100644 --- a/packages/block-editor/CHANGELOG.md +++ b/packages/block-editor/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### New Features + +- Flex layout: Add Space around and Space evenly justification options, using a menu in the Layout panel to keep all options legible ([#71129](https://github.com/WordPress/gutenberg/pull/71129)). + ### Enhancements - Inserter: Open faster when many block types are registered ([#83446](https://github.com/WordPress/gutenberg/pull/83446)). diff --git a/packages/block-editor/src/hooks/layout.scss b/packages/block-editor/src/hooks/layout.scss index 51d8ec16ebc392..1380142dea1999 100644 --- a/packages/block-editor/src/hooks/layout.scss +++ b/packages/block-editor/src/hooks/layout.scss @@ -16,6 +16,11 @@ .layout-block-support-panel { .block-editor-hooks__flex-layout-controls { grid-column: 1 / -1; + + > * { + flex: 1; + min-width: 0; + } } } @@ -28,13 +33,12 @@ } .block-editor-hooks__flex-layout-justification-controls { - display: inline-flex; - flex-wrap: wrap; - max-width: 100%; + display: grid; + gap: $grid-unit-10; - .components-toggle-group-control { - flex-wrap: wrap; - max-width: 100%; + .block-editor-hooks__flex-layout-justification-trigger { + justify-content: space-between; + width: 100%; } } diff --git a/packages/block-editor/src/layouts/flex.jsx b/packages/block-editor/src/layouts/flex.jsx index 1e49773f9ea24b..b8614b2a572686 100644 --- a/packages/block-editor/src/layouts/flex.jsx +++ b/packages/block-editor/src/layouts/flex.jsx @@ -8,6 +8,7 @@ import { justifySpaceEvenly, justifyStretch, justifyTop, + chevronDown, justifyCenterVertical, justifyBottom, justifyStretchVertical, @@ -16,12 +17,15 @@ import { arrowDown, } from '@wordpress/icons'; import { + Button, Flex, ToggleControl, __experimentalToggleGroupControl as ToggleGroupControl, __experimentalToggleGroupControlOptionIcon as ToggleGroupControlOptionIcon, __experimentalToolsPanelItem as ToolsPanelItem, } from '@wordpress/components'; +// eslint-disable-next-line @wordpress/use-recommended-components -- Menu is being adopted early for the layout control design. +import { Field, Menu } from '@wordpress/ui'; import { appendSelectors, getBlockGapCSS } from './utils'; import { getGapCSSValue, getGapBoxControlValueFromStyle } from '../hooks/gap'; import { getSpacingPresetCssVar } from '../components/spacing-sizes-control/utils'; @@ -517,17 +521,17 @@ function FlexLayoutJustifyContentControl( { { value: 'left', icon: justifyLeft, - label: __( 'Justify items left' ), + label: __( 'Left' ), }, { value: 'center', icon: justifyCenter, - label: __( 'Justify items center' ), + label: __( 'Center' ), }, { value: 'right', icon: justifyRight, - label: __( 'Justify items right' ), + label: __( 'Right' ), }, ]; if ( orientation === 'horizontal' ) { @@ -535,17 +539,17 @@ function FlexLayoutJustifyContentControl( { { value: 'space-between', icon: justifySpaceBetween, - label: __( 'Space between items' ), + label: __( 'Space between' ), }, { value: 'space-around', icon: justifySpaceAround, - label: __( 'Space around items' ), + label: __( 'Space around' ), }, { value: 'space-evenly', icon: justifySpaceEvenly, - label: __( 'Space evenly between items' ), + label: __( 'Space evenly' ), } ); } else { @@ -556,24 +560,53 @@ function FlexLayoutJustifyContentControl( { } ); } + const selectedOption = + justificationOptions.find( + ( option ) => option.value === justifyContent + ) ?? justificationOptions[ 0 ]; + return ( - - { justificationOptions.map( ( { value, icon, label } ) => { - return ( - - ); - } ) } - +
+ { __( 'Justification' ) } + + + } + > + { selectedOption.label } + + + } + > + + { justificationOptions.map( + ( { value, icon, label } ) => ( + } + > + { label } + + ) + ) } + + + +
); } diff --git a/packages/block-editor/src/layouts/test/flex.jsdom.test.jsx b/packages/block-editor/src/layouts/test/flex.jsdom.test.jsx index 6afe0e2796faa8..57edc66bd867c4 100644 --- a/packages/block-editor/src/layouts/test/flex.jsdom.test.jsx +++ b/packages/block-editor/src/layouts/test/flex.jsdom.test.jsx @@ -89,7 +89,7 @@ describe( 'getLayoutStyle', () => { describe( 'FlexLayoutInspectorControls', () => { it( 'should not render the wrap toggle by default', async () => { renderInspectorControls(); - await screen.findByRole( 'radio', { name: 'Justify items left' } ); + await screen.findByRole( 'button', { name: 'Left' } ); expect( screen.queryByRole( 'checkbox', { From b3c69e9bd4c3f8d0407953bd3cbe2c2614ef2719 Mon Sep 17 00:00:00 2001 From: Sukhendu Sekhar Guria Date: Thu, 24 Sep 2026 14:40:12 +0530 Subject: [PATCH 03/19] fix(block-editor): contain justification trigger --- packages/block-editor/src/hooks/layout.scss | 9 ++++++++- packages/block-editor/src/layouts/flex.jsx | 4 +++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/block-editor/src/hooks/layout.scss b/packages/block-editor/src/hooks/layout.scss index 1380142dea1999..1cb195a729df82 100644 --- a/packages/block-editor/src/hooks/layout.scss +++ b/packages/block-editor/src/hooks/layout.scss @@ -37,9 +37,16 @@ gap: $grid-unit-10; .block-editor-hooks__flex-layout-justification-trigger { - justify-content: space-between; width: 100%; } + + .block-editor-hooks__flex-layout-justification-label { + flex: 1; + min-width: 0; + overflow: hidden; + text-align: start; + text-overflow: ellipsis; + } } .block-editor-hooks__grid-layout-columns-and-rows-controls, diff --git a/packages/block-editor/src/layouts/flex.jsx b/packages/block-editor/src/layouts/flex.jsx index b8614b2a572686..3aceae981dd537 100644 --- a/packages/block-editor/src/layouts/flex.jsx +++ b/packages/block-editor/src/layouts/flex.jsx @@ -580,7 +580,9 @@ function FlexLayoutJustifyContentControl( { /> } > - { selectedOption.label } + + { selectedOption.label } + Date: Thu, 24 Sep 2026 14:57:51 +0530 Subject: [PATCH 04/19] fix: show full justification label --- packages/block-editor/src/hooks/layout.scss | 9 ++++++++- packages/block-editor/src/layouts/flex.jsx | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/block-editor/src/hooks/layout.scss b/packages/block-editor/src/hooks/layout.scss index 1cb195a729df82..e4d5ac0c51e763 100644 --- a/packages/block-editor/src/hooks/layout.scss +++ b/packages/block-editor/src/hooks/layout.scss @@ -18,9 +18,16 @@ grid-column: 1 / -1; > * { - flex: 1; min-width: 0; } + + .block-editor-hooks__flex-layout-justification-item { + flex: 1; + } + + .block-editor-hooks__flex-layout-orientation-item { + flex: none; + } } } diff --git a/packages/block-editor/src/layouts/flex.jsx b/packages/block-editor/src/layouts/flex.jsx index 3aceae981dd537..448c356166dbff 100644 --- a/packages/block-editor/src/layouts/flex.jsx +++ b/packages/block-editor/src/layouts/flex.jsx @@ -195,6 +195,7 @@ export default { > { allowJustification && ( Date: Thu, 24 Sep 2026 17:20:07 +0530 Subject: [PATCH 05/19] feat: support additional flex justification --- lib/block-supports/layout.php | 6 ++- packages/block-library/CHANGELOG.md | 4 ++ .../src/navigation/edit/index.jsx | 4 ++ .../layout-custom-properties.jsdom.test.js | 24 ++++++++++++ .../edit/use-layout-custom-properties.js | 2 + .../block-library/src/navigation/index.php | 4 ++ .../block-library/src/navigation/style.scss | 10 +++++ phpunit/block-supports/layout-test.php | 22 +++++++++++ ...lass-wp-navigation-block-renderer-test.php | 37 ++++++++++++++++++ .../blocks/render-block-navigation-test.php | 38 +++++++++++++++++++ 10 files changed, 150 insertions(+), 1 deletion(-) diff --git a/lib/block-supports/layout.php b/lib/block-supports/layout.php index a2448b6f7abdce..852a4d082aac74 100644 --- a/lib/block-supports/layout.php +++ b/lib/block-supports/layout.php @@ -731,7 +731,11 @@ function gutenberg_get_layout_style( $selector, $layout, $has_block_gap_support ); if ( 'horizontal' === $layout_orientation ) { - $justify_content_options += array( 'space-between' => 'space-between' ); + $justify_content_options += array( + 'space-between' => 'space-between', + 'space-around' => 'space-around', + 'space-evenly' => 'space-evenly', + ); $vertical_alignment_options += array( 'stretch' => 'stretch' ); } else { $justify_content_options += array( 'stretch' => 'stretch' ); diff --git a/packages/block-library/CHANGELOG.md b/packages/block-library/CHANGELOG.md index f794d6a8f40e02..d9eef6773cf482 100644 --- a/packages/block-library/CHANGELOG.md +++ b/packages/block-library/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### New Features + +- Navigation: Add Space around and Space evenly justification options ([#71129](https://github.com/WordPress/gutenberg/pull/71129)). + ### Enhancements - Columns: Remove the column count slider from the block settings ([#83262](https://github.com/WordPress/gutenberg/pull/83262)). diff --git a/packages/block-library/src/navigation/edit/index.jsx b/packages/block-library/src/navigation/edit/index.jsx index 68f759fa72db14..11d39954a6cb63 100644 --- a/packages/block-library/src/navigation/edit/index.jsx +++ b/packages/block-library/src/navigation/edit/index.jsx @@ -614,6 +614,10 @@ function Navigation( { 'items-justified-right': justifyContent === 'right', 'items-justified-space-between': justifyContent === 'space-between', + 'items-justified-space-around': + justifyContent === 'space-around', + 'items-justified-space-evenly': + justifyContent === 'space-evenly', 'items-justified-left': justifyContent === 'left', 'items-justified-center': justifyContent === 'center', 'is-vertical': orientation === 'vertical', diff --git a/packages/block-library/src/navigation/edit/test/layout-custom-properties.jsdom.test.js b/packages/block-library/src/navigation/edit/test/layout-custom-properties.jsdom.test.js index c4609948960240..effa86b1550f80 100644 --- a/packages/block-library/src/navigation/edit/test/layout-custom-properties.jsdom.test.js +++ b/packages/block-library/src/navigation/edit/test/layout-custom-properties.jsdom.test.js @@ -71,6 +71,30 @@ describe( 'Navigation layout custom properties', () => { } ); describe( 'responsive styles', () => { + it.each( [ 'space-around', 'space-evenly' ] )( + 'supports %s justification', + ( justifyContent ) => { + renderHook( () => + useLayoutCustomProperties( { + clientId: 'test', + style: { + '@mobile': { + layout: { justifyContent }, + }, + }, + } ) + ); + + const { css } = useStyleOverride.mock.calls.at( -1 )[ 0 ]; + expect( css ).toContain( + `--navigation-layout-justification-setting: ${ justifyContent };` + ); + expect( css ).toContain( + `--navigation-layout-justify: ${ justifyContent };` + ); + } + ); + it( 'merges viewport overrides with the base layout', () => { renderHook( () => useLayoutCustomProperties( { diff --git a/packages/block-library/src/navigation/edit/use-layout-custom-properties.js b/packages/block-library/src/navigation/edit/use-layout-custom-properties.js index b29fbaa3680a36..f6af77b99fa63c 100644 --- a/packages/block-library/src/navigation/edit/use-layout-custom-properties.js +++ b/packages/block-library/src/navigation/edit/use-layout-custom-properties.js @@ -9,6 +9,8 @@ const JUSTIFICATION_VALUES = { center: 'center', right: 'flex-end', 'space-between': 'space-between', + 'space-around': 'space-around', + 'space-evenly': 'space-evenly', }; /** diff --git a/packages/block-library/src/navigation/index.php b/packages/block-library/src/navigation/index.php index 48c1c73fd0f811..751c68cbef1f91 100644 --- a/packages/block-library/src/navigation/index.php +++ b/packages/block-library/src/navigation/index.php @@ -54,6 +54,8 @@ function block_core_navigation_get_layout_custom_property_declarations( $layout 'center' => 'center', 'right' => 'flex-end', 'space-between' => 'space-between', + 'space-around' => 'space-around', + 'space-evenly' => 'space-evenly', ); $justify_content = is_array( $layout ) ? ( $layout['justifyContent'] ?? 'left' ) : 'left'; if ( ! is_string( $justify_content ) || ! isset( $justification_values[ $justify_content ] ) ) { @@ -619,6 +621,8 @@ private static function get_layout_class( $attributes ) { 'right' => 'items-justified-right', 'center' => 'items-justified-center', 'space-between' => 'items-justified-space-between', + 'space-around' => 'items-justified-space-around', + 'space-evenly' => 'items-justified-space-evenly', ); $layout_class = ''; diff --git a/packages/block-library/src/navigation/style.scss b/packages/block-library/src/navigation/style.scss index acc0a398a678a4..8f9c381872024d 100644 --- a/packages/block-library/src/navigation/style.scss +++ b/packages/block-library/src/navigation/style.scss @@ -171,6 +171,16 @@ $navigation-icon-size: 24px; --navigation-layout-justification-setting: space-between; --navigation-layout-justify: space-between; } + + &.items-justified-space-around { + --navigation-layout-justification-setting: space-around; + --navigation-layout-justify: space-around; + } + + &.items-justified-space-evenly { + --navigation-layout-justification-setting: space-evenly; + --navigation-layout-justify: space-evenly; + } } // Low specificity padding to not override global styles. diff --git a/phpunit/block-supports/layout-test.php b/phpunit/block-supports/layout-test.php index 368a6290cc376e..b17f40cb846698 100644 --- a/phpunit/block-supports/layout-test.php +++ b/phpunit/block-supports/layout-test.php @@ -373,6 +373,28 @@ public function data_gutenberg_get_layout_style() { ), 'expected_output' => '.wp-layout{flex-wrap:nowrap;justify-content:flex-start;align-items:flex-end;}', ), + 'horizontal flex layout with space-around justification' => array( + 'args' => array( + 'selector' => '.wp-layout', + 'layout' => array( + 'type' => 'flex', + 'orientation' => 'horizontal', + 'justifyContent' => 'space-around', + ), + ), + 'expected_output' => '.wp-layout{justify-content:space-around;}', + ), + 'horizontal flex layout with space-evenly justification' => array( + 'args' => array( + 'selector' => '.wp-layout', + 'layout' => array( + 'type' => 'flex', + 'orientation' => 'horizontal', + 'justifyContent' => 'space-evenly', + ), + ), + 'expected_output' => '.wp-layout{justify-content:space-evenly;}', + ), 'flex layout with properties and block gap' => array( 'args' => array( 'selector' => '.wp-layout', diff --git a/phpunit/blocks/class-wp-navigation-block-renderer-test.php b/phpunit/blocks/class-wp-navigation-block-renderer-test.php index ed9d06c8761d71..548bdd1d1fc106 100644 --- a/phpunit/blocks/class-wp-navigation-block-renderer-test.php +++ b/phpunit/blocks/class-wp-navigation-block-renderer-test.php @@ -8,6 +8,43 @@ class WP_Navigation_Block_Renderer_Test extends WP_UnitTestCase { + /** + * Test that distributed justification values receive layout classes. + * + * @dataProvider data_distributed_justification_values + * + * @covers WP_Navigation_Block_Renderer::get_layout_class + * + * @param string $justification Justification value. + */ + public function test_get_layout_class_with_distributed_justification( $justification ) { + $reflection = new ReflectionClass( 'WP_Navigation_Block_Renderer_Gutenberg' ); + $method = $reflection->getMethod( 'get_layout_class' ); + if ( PHP_VERSION_ID < 80100 ) { + $method->setAccessible( true ); + } + + $this->assertSame( + 'items-justified-' . $justification, + $method->invoke( + $reflection, + array( 'layout' => array( 'justifyContent' => $justification ) ) + ) + ); + } + + /** + * Data provider for distributed Navigation justification values. + * + * @return array + */ + public function data_distributed_justification_values() { + return array( + 'space around' => array( 'space-around' ), + 'space evenly' => array( 'space-evenly' ), + ); + } + /** * Test that navigation links are wrapped in list items to preserve accessible markup * diff --git a/phpunit/blocks/render-block-navigation-test.php b/phpunit/blocks/render-block-navigation-test.php index c16d179a059ecf..f5ab913782138a 100644 --- a/phpunit/blocks/render-block-navigation-test.php +++ b/phpunit/blocks/render-block-navigation-test.php @@ -276,6 +276,44 @@ public function test_get_layout_custom_property_declarations() { ); } + /** + * Test that distributed justification values are converted to Navigation custom properties. + * + * @dataProvider data_distributed_justification_values + * + * @covers ::gutenberg_block_core_navigation_get_layout_custom_property_declarations + * + * @param string $justification Justification value. + */ + public function test_get_distributed_layout_custom_property_declarations( $justification ) { + $actual = gutenberg_block_core_navigation_get_layout_custom_property_declarations( + array( 'justifyContent' => $justification ) + ); + + $this->assertSame( + array( + '--navigation-layout-justification-setting' => $justification, + '--navigation-layout-direction' => 'row', + '--navigation-layout-wrap' => 'wrap', + '--navigation-layout-justify' => $justification, + '--navigation-layout-align' => 'center', + ), + $actual + ); + } + + /** + * Data provider for distributed Navigation justification values. + * + * @return array + */ + public function data_distributed_justification_values() { + return array( + 'space around' => array( 'space-around' ), + 'space evenly' => array( 'space-evenly' ), + ); + } + /** * Test responsive layout styles and classes on local Navigation containers. * From 080c9d39d454259991ca626d321ceb234b87ea7d Mon Sep 17 00:00:00 2001 From: Sukhendu Sekhar Guria Date: Thu, 24 Sep 2026 18:57:22 +0530 Subject: [PATCH 06/19] Add Core backport for #71129 --- backport-changelog/7.2/13710.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 backport-changelog/7.2/13710.md diff --git a/backport-changelog/7.2/13710.md b/backport-changelog/7.2/13710.md new file mode 100644 index 00000000000000..248426e2ffc9ed --- /dev/null +++ b/backport-changelog/7.2/13710.md @@ -0,0 +1,3 @@ +https://github.com/WordPress/wordpress-develop/pull/13710 + +* https://github.com/WordPress/gutenberg/pull/71129 From 88ccb1d37ad882b0fdeed6522479a898a825a4b4 Mon Sep 17 00:00:00 2001 From: Sukhendu Sekhar Guria Date: Fri, 25 Sep 2026 18:51:33 +0530 Subject: [PATCH 07/19] feat: refine flex justification options --- docs/explanations/architecture/styles.md | 2 ++ packages/block-editor/CHANGELOG.md | 3 +- .../justify-content-control/README.md | 10 +++--- .../test/index.jsdom.test.js | 33 +++++++++++++++++++ .../components/justify-content-control/ui.jsx | 23 ++++++++----- packages/block-editor/src/layouts/flex.jsx | 18 +++++++--- .../src/layouts/test/flex.jsdom.test.jsx | 20 +++++++++++ packages/block-library/CHANGELOG.md | 2 +- .../block-library/src/buttons/editor.scss | 2 ++ packages/block-library/src/buttons/style.scss | 10 ++++++ packages/block-library/src/common.scss | 8 +++++ 11 files changed, 113 insertions(+), 18 deletions(-) create mode 100644 packages/block-editor/src/components/justify-content-control/test/index.jsdom.test.js diff --git a/docs/explanations/architecture/styles.md b/docs/explanations/architecture/styles.md index e62ebda0fed8a4..e7cc2d0f1b6d34 100644 --- a/docs/explanations/architecture/styles.md +++ b/docs/explanations/architecture/styles.md @@ -542,6 +542,8 @@ The current semantic class names that can be output by the Layout block support - `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`. +- `is-content-justification-space-around`: When a block explicitly sets `justifyContent` to `space-around`. +- `is-content-justification-space-evenly`: When a block explicitly sets `justifyContent` to `space-evenly`. - `is-nowrap`: When a block explicitly sets `flexWrap` to `nowrap`. ### Opting out of generated layout styles diff --git a/packages/block-editor/CHANGELOG.md b/packages/block-editor/CHANGELOG.md index 7153d37776c298..e3248713926144 100644 --- a/packages/block-editor/CHANGELOG.md +++ b/packages/block-editor/CHANGELOG.md @@ -4,7 +4,8 @@ ### New Features -- Flex layout: Add Space around and Space evenly justification options, using a menu in the Layout panel to keep all options legible ([#71129](https://github.com/WordPress/gutenberg/pull/71129)). +- Flex layout: Add Space around and Space evenly justification options, using a menu with descriptions in the Layout panel to distinguish the available spacing ([#71129](https://github.com/WordPress/gutenberg/pull/71129)). +- `JustifyContentControl`: Include Space around and Space evenly in the default controls ([#71129](https://github.com/WordPress/gutenberg/pull/71129)). ### Enhancements diff --git a/packages/block-editor/src/components/justify-content-control/README.md b/packages/block-editor/src/components/justify-content-control/README.md index f8174cd097e621..041f0590b032fa 100644 --- a/packages/block-editor/src/components/justify-content-control/README.md +++ b/packages/block-editor/src/components/justify-content-control/README.md @@ -2,7 +2,7 @@ The `JustifyContentControl` component renders a toolbar that displays justify options for the selected block. -This component is used to set the flex justification for the elements in the block, allowing to justify `left`, `center`, `right`, and `space-between`. In comparison, the alignment options are for the block itself. +This component is used to set the flex justification for the elements in the block, allowing to justify `left`, `center`, `right`, `space-between`, `space-around`, and `space-evenly`. In comparison, the alignment options are for the block itself. See the Navigation block for an example usage. @@ -33,6 +33,8 @@ const MyJustifyToolbar = ( { attributes, setAttributes } ) => ( items-justified-center items-justified-right items-justified-space-between + items-justified-space-around + items-justified-space-evenly _Note:_ In this example that we render `JustifyContentControl` as a child of the `BlockControls` component. @@ -41,7 +43,7 @@ _Note:_ In this example that we render `JustifyContentControl` as a child of the #### `allowedControls` - **Type:** `string[]` -- **Default:** `[ 'left', 'center', 'right', 'space-between' ]` +- **Default:** `[ 'left', 'center', 'right', 'space-between', 'space-around', 'space-evenly' ]` An array of strings for what controls to show, by default it shows all. @@ -50,7 +52,7 @@ An array of strings for what controls to show, by default it shows all. - **Type:** `Function` - **Required:** Yes -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. +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`, `space-around`, `space-evenly`, `undefined`) as the only argument. #### `popoverProps` @@ -65,7 +67,7 @@ Use this object to modify props available for the `Popover` component that are n - **Type:** `String` - **Default:** `undefined` -- **Options:**: `left`, `center`, `right`, `space-between` +- **Options:**: `left`, `center`, `right`, `space-between`, `space-around`, `space-evenly` The current value of the alignment setting. You may only choose from the `Options` listed above. diff --git a/packages/block-editor/src/components/justify-content-control/test/index.jsdom.test.js b/packages/block-editor/src/components/justify-content-control/test/index.jsdom.test.js new file mode 100644 index 00000000000000..8cfdaf74eeff8d --- /dev/null +++ b/packages/block-editor/src/components/justify-content-control/test/index.jsdom.test.js @@ -0,0 +1,33 @@ +import { expect, test, vi } from 'vitest'; +import { render, screen } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; +import { createElement } from '@wordpress/element'; +import JustifyContentUI from '../ui'; + +test( 'lists every justification option by default', async () => { + const user = userEvent.setup(); + const { unmount } = render( + createElement( JustifyContentUI, { + value: 'left', + onChange: vi.fn(), + } ) + ); + + await user.click( + screen.getByRole( 'button', { name: 'Change items justification' } ) + ); + + expect( + screen.getAllByRole( 'menuitem' ).map( ( item ) => item.textContent ) + ).toEqual( [ + 'Left', + 'Center', + 'Right', + 'Space between', + 'Space around', + 'Space evenly', + ] ); + + // Cancel delayed popover positioning effects. + unmount(); +} ); diff --git a/packages/block-editor/src/components/justify-content-control/ui.jsx b/packages/block-editor/src/components/justify-content-control/ui.jsx index aaca9b60ffca2f..026735829b3a5a 100644 --- a/packages/block-editor/src/components/justify-content-control/ui.jsx +++ b/packages/block-editor/src/components/justify-content-control/ui.jsx @@ -8,7 +8,7 @@ import { justifySpaceEvenly, justifyStretch, } from '@wordpress/icons'; -import { __ } from '@wordpress/i18n'; +import { __, _x } from '@wordpress/i18n'; const icons = { left: justifyLeft, @@ -21,7 +21,14 @@ const icons = { }; function JustifyContentUI( { - allowedControls = [ 'left', 'center', 'right', 'space-between' ], + allowedControls = [ + 'left', + 'center', + 'right', + 'space-between', + 'space-around', + 'space-evenly', + ], isCollapsed = true, onChange, value, @@ -44,42 +51,42 @@ function JustifyContentUI( { { name: 'left', icon: justifyLeft, - title: __( 'Justify items left' ), + title: _x( 'Left', 'Flex layout justification option' ), isActive: 'left' === value, onClick: () => handleClick( 'left' ), }, { name: 'center', icon: justifyCenter, - title: __( 'Justify items center' ), + title: _x( 'Center', 'Flex layout justification option' ), isActive: 'center' === value, onClick: () => handleClick( 'center' ), }, { name: 'right', icon: justifyRight, - title: __( 'Justify items right' ), + title: _x( 'Right', 'Flex layout justification option' ), isActive: 'right' === value, onClick: () => handleClick( 'right' ), }, { name: 'space-between', icon: justifySpaceBetween, - title: __( 'Space between items' ), + title: __( 'Space between' ), isActive: 'space-between' === value, onClick: () => handleClick( 'space-between' ), }, { name: 'space-around', icon: justifySpaceAround, - title: __( 'Space around items' ), + title: __( 'Space around' ), isActive: 'space-around' === value, onClick: () => handleClick( 'space-around' ), }, { name: 'space-evenly', icon: justifySpaceEvenly, - title: __( 'Space evenly between items' ), + title: __( 'Space evenly' ), isActive: 'space-evenly' === value, onClick: () => handleClick( 'space-evenly' ), }, diff --git a/packages/block-editor/src/layouts/flex.jsx b/packages/block-editor/src/layouts/flex.jsx index 448c356166dbff..32eb422961360a 100644 --- a/packages/block-editor/src/layouts/flex.jsx +++ b/packages/block-editor/src/layouts/flex.jsx @@ -523,17 +523,20 @@ function FlexLayoutJustifyContentControl( { { value: 'left', icon: justifyLeft, - label: __( 'Left' ), + label: _x( 'Left', 'Flex layout justification option' ), + description: __( 'Space after the items.' ), }, { value: 'center', icon: justifyCenter, - label: __( 'Center' ), + label: _x( 'Center', 'Flex layout justification option' ), + description: __( 'Space on both sides.' ), }, { value: 'right', icon: justifyRight, - label: __( 'Right' ), + label: _x( 'Right', 'Flex layout justification option' ), + description: __( 'Space before the items.' ), }, ]; if ( orientation === 'horizontal' ) { @@ -542,16 +545,19 @@ function FlexLayoutJustifyContentControl( { value: 'space-between', icon: justifySpaceBetween, label: __( 'Space between' ), + description: __( 'No space at the edges.' ), }, { value: 'space-around', icon: justifySpaceAround, label: __( 'Space around' ), + description: __( 'Half space at the edges.' ), }, { value: 'space-evenly', icon: justifySpaceEvenly, label: __( 'Space evenly' ), + description: __( 'Equal space at the edges.' ), } ); } else { @@ -559,6 +565,7 @@ function FlexLayoutJustifyContentControl( { value: 'stretch', icon: justifyStretch, label: __( 'Stretch items' ), + description: __( 'Fill the available space.' ), } ); } @@ -597,13 +604,16 @@ function FlexLayoutJustifyContentControl( { onValueChange={ onJustificationChange } > { justificationOptions.map( - ( { value, icon, label } ) => ( + ( { value, icon, label, description } ) => ( } > { label } + + { description } + ) ) } diff --git a/packages/block-editor/src/layouts/test/flex.jsdom.test.jsx b/packages/block-editor/src/layouts/test/flex.jsdom.test.jsx index 57edc66bd867c4..0663919a39dfbb 100644 --- a/packages/block-editor/src/layouts/test/flex.jsdom.test.jsx +++ b/packages/block-editor/src/layouts/test/flex.jsdom.test.jsx @@ -87,6 +87,26 @@ describe( 'getLayoutStyle', () => { } ); describe( 'FlexLayoutInspectorControls', () => { + it( 'should describe each justification option', async () => { + const user = userEvent.setup(); + renderInspectorControls(); + + await user.click( + await screen.findByRole( 'button', { name: 'Left' } ) + ); + + for ( const description of [ + 'Space after the items.', + 'Space on both sides.', + 'Space before the items.', + 'No space at the edges.', + 'Half space at the edges.', + 'Equal space at the edges.', + ] ) { + expect( await screen.findByText( description ) ).toBeVisible(); + } + } ); + it( 'should not render the wrap toggle by default', async () => { renderInspectorControls(); await screen.findByRole( 'button', { name: 'Left' } ); diff --git a/packages/block-library/CHANGELOG.md b/packages/block-library/CHANGELOG.md index d9eef6773cf482..be7eeef4141dc3 100644 --- a/packages/block-library/CHANGELOG.md +++ b/packages/block-library/CHANGELOG.md @@ -4,7 +4,7 @@ ### New Features -- Navigation: Add Space around and Space evenly justification options ([#71129](https://github.com/WordPress/gutenberg/pull/71129)). +- Buttons and Navigation: Add Space around and Space evenly justification options ([#71129](https://github.com/WordPress/gutenberg/pull/71129)). ### Enhancements diff --git a/packages/block-library/src/buttons/editor.scss b/packages/block-library/src/buttons/editor.scss index f0a1e930d40bb8..2b580b03f9dfed 100644 --- a/packages/block-library/src/buttons/editor.scss +++ b/packages/block-library/src/buttons/editor.scss @@ -36,6 +36,8 @@ $blocks-block__margin: 0.5em; /* stylelint-disable @stylistic/indentation -- Disable the stylelint rule, otherwise this selector is ugly! */ &:not( .is-content-justification-space-between, + .is-content-justification-space-around, + .is-content-justification-space-evenly, .is-content-justification-right, .is-content-justification-left, .is-content-justification-center diff --git a/packages/block-library/src/buttons/style.scss b/packages/block-library/src/buttons/style.scss index fa9c96aef1710b..659fb6d648635e 100644 --- a/packages/block-library/src/buttons/style.scss +++ b/packages/block-library/src/buttons/style.scss @@ -46,6 +46,14 @@ $blocks-block__margin: 0.5em; justify-content: space-between; } + &.is-content-justification-space-around { + justify-content: space-around; + } + + &.is-content-justification-space-evenly { + justify-content: space-evenly; + } + // Kept for backward compatibility. &.aligncenter { text-align: center; @@ -60,6 +68,8 @@ $blocks-block__margin: 0.5em; /* stylelint-disable @stylistic/indentation -- Disable the stylelint rule, otherwise this selector is ugly! */ &:not( .is-content-justification-space-between, + .is-content-justification-space-around, + .is-content-justification-space-evenly, .is-content-justification-right, .is-content-justification-left, .is-content-justification-center diff --git a/packages/block-library/src/common.scss b/packages/block-library/src/common.scss index ee2e86f2678c5c..f8d6e0de33f2ea 100644 --- a/packages/block-library/src/common.scss +++ b/packages/block-library/src/common.scss @@ -82,6 +82,14 @@ justify-content: space-between; } +.items-justified-space-around { + justify-content: space-around; +} + +.items-justified-space-evenly { + justify-content: space-evenly; +} + .screen-reader-text { border: 0; clip-path: inset(50%); From 10528442c7141db4362d2411385210ca1d10941b Mon Sep 17 00:00:00 2001 From: Sukhendu Sekhar Guria Date: Mon, 28 Sep 2026 10:51:24 +0530 Subject: [PATCH 08/19] fix: complete flex justification support --- packages/block-editor/src/hooks/layout.scss | 17 ----- packages/block-editor/src/layouts/flex.jsx | 74 +++---------------- .../src/layouts/test/flex.jsdom.test.jsx | 21 +++++- .../block-library/src/navigation/style.scss | 6 +- .../block-library/src/page-list/editor.scss | 6 +- schemas/json/block.json | 2 + 6 files changed, 40 insertions(+), 86 deletions(-) diff --git a/packages/block-editor/src/hooks/layout.scss b/packages/block-editor/src/hooks/layout.scss index e4d5ac0c51e763..f39cb4514ef41b 100644 --- a/packages/block-editor/src/hooks/layout.scss +++ b/packages/block-editor/src/hooks/layout.scss @@ -39,23 +39,6 @@ } } -.block-editor-hooks__flex-layout-justification-controls { - display: grid; - gap: $grid-unit-10; - - .block-editor-hooks__flex-layout-justification-trigger { - width: 100%; - } - - .block-editor-hooks__flex-layout-justification-label { - flex: 1; - min-width: 0; - overflow: hidden; - text-align: start; - text-overflow: ellipsis; - } -} - .block-editor-hooks__grid-layout-columns-and-rows-controls, .block-editor-hooks__grid-layout-minimum-width-control { // Reset `fieldset` browser defaults. diff --git a/packages/block-editor/src/layouts/flex.jsx b/packages/block-editor/src/layouts/flex.jsx index 32eb422961360a..17de45feac28e4 100644 --- a/packages/block-editor/src/layouts/flex.jsx +++ b/packages/block-editor/src/layouts/flex.jsx @@ -1,14 +1,6 @@ import { __, _x } from '@wordpress/i18n'; import { - justifyLeft, - justifyCenter, - justifyRight, - justifySpaceBetween, - justifySpaceAround, - justifySpaceEvenly, - justifyStretch, justifyTop, - chevronDown, justifyCenterVertical, justifyBottom, justifyStretchVertical, @@ -17,15 +9,13 @@ import { arrowDown, } from '@wordpress/icons'; import { - Button, Flex, ToggleControl, __experimentalToggleGroupControl as ToggleGroupControl, __experimentalToggleGroupControlOptionIcon as ToggleGroupControlOptionIcon, __experimentalToolsPanelItem as ToolsPanelItem, } from '@wordpress/components'; -// eslint-disable-next-line @wordpress/use-recommended-components -- Menu is being adopted early for the layout control design. -import { Field, Menu } from '@wordpress/ui'; +import { SelectControl } from '@wordpress/ui'; import { appendSelectors, getBlockGapCSS } from './utils'; import { getGapCSSValue, getGapBoxControlValueFromStyle } from '../hooks/gap'; import { getSpacingPresetCssVar } from '../components/spacing-sizes-control/utils'; @@ -522,19 +512,16 @@ function FlexLayoutJustifyContentControl( { const justificationOptions = [ { value: 'left', - icon: justifyLeft, label: _x( 'Left', 'Flex layout justification option' ), description: __( 'Space after the items.' ), }, { value: 'center', - icon: justifyCenter, label: _x( 'Center', 'Flex layout justification option' ), description: __( 'Space on both sides.' ), }, { value: 'right', - icon: justifyRight, label: _x( 'Right', 'Flex layout justification option' ), description: __( 'Space before the items.' ), }, @@ -543,19 +530,16 @@ function FlexLayoutJustifyContentControl( { justificationOptions.push( { value: 'space-between', - icon: justifySpaceBetween, label: __( 'Space between' ), description: __( 'No space at the edges.' ), }, { value: 'space-around', - icon: justifySpaceAround, label: __( 'Space around' ), description: __( 'Half space at the edges.' ), }, { value: 'space-evenly', - icon: justifySpaceEvenly, label: __( 'Space evenly' ), description: __( 'Equal space at the edges.' ), } @@ -563,7 +547,6 @@ function FlexLayoutJustifyContentControl( { } else { justificationOptions.push( { value: 'stretch', - icon: justifyStretch, label: __( 'Stretch items' ), description: __( 'Fill the available space.' ), } ); @@ -575,52 +558,15 @@ function FlexLayoutJustifyContentControl( { ) ?? justificationOptions[ 0 ]; return ( -
- { __( 'Justification' ) } - - - } - > - - { selectedOption.label } - - - - } - > - - { justificationOptions.map( - ( { value, icon, label, description } ) => ( - } - > - { label } - - { description } - - - ) - ) } - - - -
+ + onJustificationChange( selectedItem.value ) + } + /> ); } diff --git a/packages/block-editor/src/layouts/test/flex.jsdom.test.jsx b/packages/block-editor/src/layouts/test/flex.jsdom.test.jsx index 0663919a39dfbb..02a1dd48cc0455 100644 --- a/packages/block-editor/src/layouts/test/flex.jsdom.test.jsx +++ b/packages/block-editor/src/layouts/test/flex.jsdom.test.jsx @@ -92,7 +92,7 @@ describe( 'FlexLayoutInspectorControls', () => { renderInspectorControls(); await user.click( - await screen.findByRole( 'button', { name: 'Left' } ) + await screen.findByRole( 'combobox', { name: 'Justification' } ) ); for ( const description of [ @@ -107,9 +107,26 @@ describe( 'FlexLayoutInspectorControls', () => { } } ); + it( 'should update the justification from the select control', async () => { + const user = userEvent.setup(); + const onChange = vi.fn(); + renderInspectorControls( { onChange } ); + + await user.click( + await screen.findByRole( 'combobox', { name: 'Justification' } ) + ); + await user.click( + await screen.findByRole( 'option', { name: 'Space around' } ) + ); + + expect( onChange ).toHaveBeenCalledWith( { + justifyContent: 'space-around', + } ); + } ); + it( 'should not render the wrap toggle by default', async () => { renderInspectorControls(); - await screen.findByRole( 'button', { name: 'Left' } ); + await screen.findByRole( 'combobox', { name: 'Justification' } ); expect( screen.queryByRole( 'checkbox', { diff --git a/packages/block-library/src/navigation/style.scss b/packages/block-library/src/navigation/style.scss index 8f9c381872024d..1ecd506d61ae27 100644 --- a/packages/block-library/src/navigation/style.scss +++ b/packages/block-library/src/navigation/style.scss @@ -468,11 +468,15 @@ button.wp-block-navigation-item__content { * Justifications. */ -// When justified space-between, open submenus leftward for last menu item. +// When using distributed justification, 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-space-around .wp-block-page-list > .has-child:last-child, +.wp-block-navigation.items-justified-space-around > .wp-block-navigation__container > .has-child:last-child, +.wp-block-navigation.items-justified-space-evenly .wp-block-page-list > .has-child:last-child, +.wp-block-navigation.items-justified-space-evenly > .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 { // First submenu. diff --git a/packages/block-library/src/page-list/editor.scss b/packages/block-library/src/page-list/editor.scss index 34ce584a11441e..bc2d606cd3ad56 100644 --- a/packages/block-library/src/page-list/editor.scss +++ b/packages/block-library/src/page-list/editor.scss @@ -1,8 +1,10 @@ @use "@wordpress/base-styles/variables" as *; .wp-block-navigation { - // space-between justification. - &.items-justified-space-between { + // Distributed justification. + &.items-justified-space-between, + &.items-justified-space-around, + &.items-justified-space-evenly { .wp-block-page-list > div, .wp-block-page-list { display: contents; diff --git a/schemas/json/block.json b/schemas/json/block.json index 40b6b6f6fae2e2..7f4d832305dc5a 100644 --- a/schemas/json/block.json +++ b/schemas/json/block.json @@ -454,6 +454,8 @@ "right", "center", "space-between", + "space-around", + "space-evenly", "left", "stretch" ] From 46b0f74d4935e46728ddf67105dd51b9a6a7fe81 Mon Sep 17 00:00:00 2001 From: Sukhendu Sekhar Guria Date: Wed, 14 Oct 2026 18:54:51 +0530 Subject: [PATCH 09/19] fix: prevent Justification select crash on Stack to Row switch and cover all options in tests --- packages/block-editor/CHANGELOG.md | 2 +- packages/block-editor/src/layouts/flex.jsx | 9 ++-- .../src/layouts/test/flex.jsdom.test.jsx | 38 ++++++++++++++ packages/block-library/CHANGELOG.md | 4 -- .../layout-custom-properties.jsdom.test.js | 50 +++++++++++-------- ...lass-wp-navigation-block-renderer-test.php | 37 -------------- .../blocks/render-block-navigation-test.php | 27 ++++++---- 7 files changed, 89 insertions(+), 78 deletions(-) diff --git a/packages/block-editor/CHANGELOG.md b/packages/block-editor/CHANGELOG.md index a78a60ecd90996..f827bb750a64ba 100644 --- a/packages/block-editor/CHANGELOG.md +++ b/packages/block-editor/CHANGELOG.md @@ -4,7 +4,7 @@ ### New Features -- Flex layout: Add Space around and Space evenly justification options, using a menu with descriptions in the Layout panel to distinguish the available spacing ([#71129](https://github.com/WordPress/gutenberg/pull/71129)). +- Flex layout: Add Space around and Space evenly justification options, using a select control with descriptions in the Layout panel to distinguish the available spacing ([#71129](https://github.com/WordPress/gutenberg/pull/71129)). - `JustifyContentControl`: Include Space around and Space evenly in the default controls ([#71129](https://github.com/WordPress/gutenberg/pull/71129)). ### Enhancements diff --git a/packages/block-editor/src/layouts/flex.jsx b/packages/block-editor/src/layouts/flex.jsx index 17de45feac28e4..9ec29334e92a43 100644 --- a/packages/block-editor/src/layouts/flex.jsx +++ b/packages/block-editor/src/layouts/flex.jsx @@ -563,9 +563,12 @@ function FlexLayoutJustifyContentControl( { label={ __( 'Justification' ) } items={ justificationOptions } value={ selectedOption } - onValueChange={ ( selectedItem ) => - onJustificationChange( selectedItem.value ) - } + isItemEqualToValue={ ( item, value ) => item.value === value.value } + onValueChange={ ( selectedItem ) => { + if ( selectedItem ) { + onJustificationChange( selectedItem.value ); + } + } } /> ); } diff --git a/packages/block-editor/src/layouts/test/flex.jsdom.test.jsx b/packages/block-editor/src/layouts/test/flex.jsdom.test.jsx index 02a1dd48cc0455..cec25f891b01ca 100644 --- a/packages/block-editor/src/layouts/test/flex.jsdom.test.jsx +++ b/packages/block-editor/src/layouts/test/flex.jsdom.test.jsx @@ -124,6 +124,44 @@ describe( 'FlexLayoutInspectorControls', () => { } ); } ); + it( 'should not crash when the selected justification becomes unavailable', async () => { + const user = userEvent.setup(); + const onChange = vi.fn(); + const renderControls = ( layout ) => ( + + + + ); + const { rerender } = render( + renderControls( { orientation: 'vertical' } ) + ); + + await user.click( + await screen.findByRole( 'combobox', { name: 'Justification' } ) + ); + await user.click( + await screen.findByRole( 'option', { name: /Stretch items/ } ) + ); + expect( onChange ).toHaveBeenLastCalledWith( { + orientation: 'vertical', + justifyContent: 'stretch', + } ); + + rerender( renderControls( { justifyContent: 'stretch' } ) ); + + expect( + await screen.findByRole( 'combobox', { name: 'Justification' } ) + ).toHaveTextContent( 'Left' ); + } ); + it( 'should not render the wrap toggle by default', async () => { renderInspectorControls(); await screen.findByRole( 'combobox', { name: 'Justification' } ); diff --git a/packages/block-library/CHANGELOG.md b/packages/block-library/CHANGELOG.md index 9cd220f83c488d..4672445dda0624 100644 --- a/packages/block-library/CHANGELOG.md +++ b/packages/block-library/CHANGELOG.md @@ -2,10 +2,6 @@ ## Unreleased -### New Features - -- Buttons and Navigation: Add Space around and Space evenly justification options ([#71129](https://github.com/WordPress/gutenberg/pull/71129)). - ### Enhancements - Columns: Remove the column count slider from the block settings ([#83262](https://github.com/WordPress/gutenberg/pull/83262)). diff --git a/packages/block-library/src/navigation/edit/test/layout-custom-properties.jsdom.test.js b/packages/block-library/src/navigation/edit/test/layout-custom-properties.jsdom.test.js index effa86b1550f80..9e1bf7a92823ec 100644 --- a/packages/block-library/src/navigation/edit/test/layout-custom-properties.jsdom.test.js +++ b/packages/block-library/src/navigation/edit/test/layout-custom-properties.jsdom.test.js @@ -70,31 +70,37 @@ describe( 'Navigation layout custom properties', () => { ); } ); - describe( 'responsive styles', () => { - it.each( [ 'space-around', 'space-evenly' ] )( - 'supports %s justification', - ( justifyContent ) => { - renderHook( () => - useLayoutCustomProperties( { - clientId: 'test', - style: { - '@mobile': { - layout: { justifyContent }, - }, + describe( 'horizontal layouts', () => { + it.each( [ + [ 'left', 'flex-start' ], + [ 'center', 'center' ], + [ 'right', 'flex-end' ], + [ 'space-between', 'space-between' ], + [ 'space-around', 'space-around' ], + [ 'space-evenly', 'space-evenly' ], + ] )( 'maps %s justification to %s', ( justifyContent, justify ) => { + renderHook( () => + useLayoutCustomProperties( { + clientId: 'test', + style: { + '@mobile': { + layout: { justifyContent }, }, - } ) - ); + }, + } ) + ); - const { css } = useStyleOverride.mock.calls.at( -1 )[ 0 ]; - expect( css ).toContain( - `--navigation-layout-justification-setting: ${ justifyContent };` - ); - expect( css ).toContain( - `--navigation-layout-justify: ${ justifyContent };` - ); - } - ); + const { css } = useStyleOverride.mock.calls.at( -1 )[ 0 ]; + expect( css ).toContain( + `--navigation-layout-justification-setting: ${ justify };` + ); + expect( css ).toContain( + `--navigation-layout-justify: ${ justify };` + ); + } ); + } ); + describe( 'responsive styles', () => { it( 'merges viewport overrides with the base layout', () => { renderHook( () => useLayoutCustomProperties( { diff --git a/phpunit/blocks/class-wp-navigation-block-renderer-test.php b/phpunit/blocks/class-wp-navigation-block-renderer-test.php index 548bdd1d1fc106..ed9d06c8761d71 100644 --- a/phpunit/blocks/class-wp-navigation-block-renderer-test.php +++ b/phpunit/blocks/class-wp-navigation-block-renderer-test.php @@ -8,43 +8,6 @@ class WP_Navigation_Block_Renderer_Test extends WP_UnitTestCase { - /** - * Test that distributed justification values receive layout classes. - * - * @dataProvider data_distributed_justification_values - * - * @covers WP_Navigation_Block_Renderer::get_layout_class - * - * @param string $justification Justification value. - */ - public function test_get_layout_class_with_distributed_justification( $justification ) { - $reflection = new ReflectionClass( 'WP_Navigation_Block_Renderer_Gutenberg' ); - $method = $reflection->getMethod( 'get_layout_class' ); - if ( PHP_VERSION_ID < 80100 ) { - $method->setAccessible( true ); - } - - $this->assertSame( - 'items-justified-' . $justification, - $method->invoke( - $reflection, - array( 'layout' => array( 'justifyContent' => $justification ) ) - ) - ); - } - - /** - * Data provider for distributed Navigation justification values. - * - * @return array - */ - public function data_distributed_justification_values() { - return array( - 'space around' => array( 'space-around' ), - 'space evenly' => array( 'space-evenly' ), - ); - } - /** * Test that navigation links are wrapped in list items to preserve accessible markup * diff --git a/phpunit/blocks/render-block-navigation-test.php b/phpunit/blocks/render-block-navigation-test.php index f5ab913782138a..911596c71f29e2 100644 --- a/phpunit/blocks/render-block-navigation-test.php +++ b/phpunit/blocks/render-block-navigation-test.php @@ -277,25 +277,26 @@ public function test_get_layout_custom_property_declarations() { } /** - * Test that distributed justification values are converted to Navigation custom properties. + * Test that horizontal justification values are mapped to Navigation custom properties. * - * @dataProvider data_distributed_justification_values + * @dataProvider data_horizontal_justification_values * * @covers ::gutenberg_block_core_navigation_get_layout_custom_property_declarations * - * @param string $justification Justification value. + * @param string $justify_content Justification value. + * @param string $justify Expected CSS value. */ - public function test_get_distributed_layout_custom_property_declarations( $justification ) { + public function test_get_horizontal_layout_custom_property_declarations( $justify_content, $justify ) { $actual = gutenberg_block_core_navigation_get_layout_custom_property_declarations( - array( 'justifyContent' => $justification ) + array( 'justifyContent' => $justify_content ) ); $this->assertSame( array( - '--navigation-layout-justification-setting' => $justification, + '--navigation-layout-justification-setting' => $justify, '--navigation-layout-direction' => 'row', '--navigation-layout-wrap' => 'wrap', - '--navigation-layout-justify' => $justification, + '--navigation-layout-justify' => $justify, '--navigation-layout-align' => 'center', ), $actual @@ -303,14 +304,18 @@ public function test_get_distributed_layout_custom_property_declarations( $justi } /** - * Data provider for distributed Navigation justification values. + * Data provider for horizontal Navigation justification values. * * @return array */ - public function data_distributed_justification_values() { + public function data_horizontal_justification_values() { return array( - 'space around' => array( 'space-around' ), - 'space evenly' => array( 'space-evenly' ), + 'left' => array( 'left', 'flex-start' ), + 'center' => array( 'center', 'center' ), + 'right' => array( 'right', 'flex-end' ), + 'space between' => array( 'space-between', 'space-between' ), + 'space around' => array( 'space-around', 'space-around' ), + 'space evenly' => array( 'space-evenly', 'space-evenly' ), ); } From 279f5b9f3375055575e025c1925706456218cad1 Mon Sep 17 00:00:00 2001 From: Sukhendu Sekhar Guria Date: Fri, 23 Oct 2026 23:06:58 +0530 Subject: [PATCH 10/19] docs: move justification notes to Unreleased --- packages/block-editor/CHANGELOG.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/block-editor/CHANGELOG.md b/packages/block-editor/CHANGELOG.md index f394d1a0cc4b09..e6fac8ef907db8 100644 --- a/packages/block-editor/CHANGELOG.md +++ b/packages/block-editor/CHANGELOG.md @@ -2,6 +2,11 @@ ## Unreleased +### New Features + +- Flex layout: Add Space around and Space evenly justification options, using a select control with icons and labels in the Layout panel ([#71129](https://github.com/WordPress/gutenberg/pull/71129)). +- `JustifyContentControl`: Include Space around and Space evenly in the default controls ([#71129](https://github.com/WordPress/gutenberg/pull/71129)). + ### Enhancements - Publish the package's TypeScript declarations, so consumers get its types ([#85036](https://github.com/WordPress/gutenberg/pull/85036)). @@ -43,8 +48,6 @@ ### New Features -- Flex layout: Add Space around and Space evenly justification options, using a select control with icons and labels in the Layout panel ([#71129](https://github.com/WordPress/gutenberg/pull/71129)). -- `JustifyContentControl`: Include Space around and Space evenly in the default controls ([#71129](https://github.com/WordPress/gutenberg/pull/71129)). - Typography: Add a Gradient control that fills the text with a gradient, shown when `settings.background.backgroundClip` allows the `text` value, or when the block declares the support and a theme has not set it ([#77142](https://github.com/WordPress/gutenberg/pull/77142)). - Background: Add a Clip control for choosing the box a background is painted into, shown when `settings.background.backgroundClip` allows a value other than `text` ([#77142](https://github.com/WordPress/gutenberg/pull/77142)). From c532c77998fd03fc62e6eb5692ba6657b389a63d Mon Sep 17 00:00:00 2001 From: Sukhendu Sekhar Guria Date: Fri, 23 Oct 2026 23:43:50 +0530 Subject: [PATCH 11/19] test: migrate justification test to TypeScript --- .../test/{index.jsdom.test.js => index.jsdom.test.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename packages/block-editor/src/components/justify-content-control/test/{index.jsdom.test.js => index.jsdom.test.ts} (100%) diff --git a/packages/block-editor/src/components/justify-content-control/test/index.jsdom.test.js b/packages/block-editor/src/components/justify-content-control/test/index.jsdom.test.ts similarity index 100% rename from packages/block-editor/src/components/justify-content-control/test/index.jsdom.test.js rename to packages/block-editor/src/components/justify-content-control/test/index.jsdom.test.ts From db25d85a51c75f6b9b5506fde09c305dbfddbbcb Mon Sep 17 00:00:00 2001 From: Sukhendu Sekhar Guria Date: Tue, 3 Nov 2026 12:03:38 +0530 Subject: [PATCH 12/19] fix: simplify flex justification controls --- packages/block-editor/src/layouts/flex.tsx | 25 +------- .../src/layouts/test/flex.jsdom.test.tsx | 64 +------------------ 2 files changed, 4 insertions(+), 85 deletions(-) diff --git a/packages/block-editor/src/layouts/flex.tsx b/packages/block-editor/src/layouts/flex.tsx index c958a7b59074fd..86790c8429716d 100644 --- a/packages/block-editor/src/layouts/flex.tsx +++ b/packages/block-editor/src/layouts/flex.tsx @@ -202,7 +202,7 @@ export default { { allowJustification && ( @@ -608,29 +608,6 @@ function FlexLayoutJustifyContentControl( { label={ __( 'Justification' ) } items={ justificationOptions } value={ selectedOption } - trigger={ - - } - direction="row" - align="center" - gap="xs" - > - - - { selectedOption.label } - - - - } isItemEqualToValue={ ( item, value ) => item.value === value.value } onValueChange={ ( selectedItem ) => { if ( selectedItem && selectedItem.value !== null ) { diff --git a/packages/block-editor/src/layouts/test/flex.jsdom.test.tsx b/packages/block-editor/src/layouts/test/flex.jsdom.test.tsx index 4e17097fcfe8fc..a8611758d4d128 100644 --- a/packages/block-editor/src/layouts/test/flex.jsdom.test.tsx +++ b/packages/block-editor/src/layouts/test/flex.jsdom.test.tsx @@ -3,7 +3,6 @@ import { render, screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import { __experimentalToolsPanel as ToolsPanel } from '@wordpress/components'; import flex from '../flex'; -import type { Layout } from '../types'; globalThis.wpVitest.mockMatchMedia(); @@ -88,35 +87,6 @@ describe( 'getLayoutStyle', () => { } ); describe( 'FlexLayoutInspectorControls', () => { - it( 'should show icons and labels without descriptions', async () => { - const user = userEvent.setup(); - renderInspectorControls(); - - const trigger = await screen.findByRole( 'combobox', { - name: 'Justification', - } ); - expect( trigger ).toHaveTextContent( 'Left' ); - // eslint-disable-next-line testing-library/no-node-access -- Decorative icons have no accessible role; includes the caret. - expect( trigger.querySelectorAll( 'svg' ) ).toHaveLength( 2 ); - - await user.click( trigger ); - - for ( const label of [ - 'Left', - 'Center', - 'Right', - 'Space between', - 'Space around', - 'Space evenly', - ] ) { - const option = await screen.findByRole( 'option', { name: label } ); - expect( option ).toBeVisible(); - expect( option ).not.toHaveAttribute( 'aria-describedby' ); - // eslint-disable-next-line testing-library/no-node-access -- Decorative icons have no accessible role; includes the selection indicator. - expect( option.querySelectorAll( 'svg' ) ).toHaveLength( 2 ); - } - } ); - it( 'should update the justification from the select control', async () => { const user = userEvent.setup(); const onChange = vi.fn(); @@ -134,39 +104,11 @@ describe( 'FlexLayoutInspectorControls', () => { } ); } ); - it( 'should not crash when the selected justification becomes unavailable', async () => { - const user = userEvent.setup(); - const onChange = vi.fn(); - const renderControls = ( layout: Layout ) => ( - - - - ); - const { rerender } = render( - renderControls( { orientation: 'vertical' } ) - ); - - await user.click( - await screen.findByRole( 'combobox', { name: 'Justification' } ) - ); - await user.click( - await screen.findByRole( 'option', { name: /Stretch items/ } ) - ); - expect( onChange ).toHaveBeenLastCalledWith( { - orientation: 'vertical', - justifyContent: 'stretch', + it( 'should fall back to the first option when the justification is not available for the orientation', async () => { + renderInspectorControls( { + layout: { orientation: 'horizontal', justifyContent: 'stretch' }, } ); - rerender( renderControls( { justifyContent: 'stretch' } ) ); - expect( await screen.findByRole( 'combobox', { name: 'Justification' } ) ).toHaveTextContent( 'Left' ); From 6746008060d2d68ad8e89f77f3a85b401607b144 Mon Sep 17 00:00:00 2001 From: Sukhendu Sekhar Guria Date: Mon, 30 Nov 2026 12:53:31 +0530 Subject: [PATCH 13/19] fix: move changelog entries to Unreleased --- packages/block-editor/CHANGELOG.md | 7 ++-- .../test/index.jsdom.test.ts | 33 ------------------- packages/block-editor/src/layouts/flex.tsx | 2 +- 3 files changed, 3 insertions(+), 39 deletions(-) delete mode 100644 packages/block-editor/src/components/justify-content-control/test/index.jsdom.test.ts diff --git a/packages/block-editor/CHANGELOG.md b/packages/block-editor/CHANGELOG.md index a1863a877475f7..bf21779b04b0c8 100644 --- a/packages/block-editor/CHANGELOG.md +++ b/packages/block-editor/CHANGELOG.md @@ -8,6 +8,8 @@ - Add `getTransformClassesAndStyles()`, for blocks that apply transform styles to an inner element ([#86240](https://github.com/WordPress/gutenberg/pull/86240)). - Add an Offset control with X and Y axes to the Transform panel, for the `transform.translate` block support ([#86282](https://github.com/WordPress/gutenberg/pull/86282)). - Add a Scale control to the Transform panel, for the `transform.scale` block support ([#86727](https://github.com/WordPress/gutenberg/pull/86727)). +- Flex layout: Add Space around and Space evenly justification options, using a select control with icons and labels in the Layout panel ([#71129](https://github.com/WordPress/gutenberg/pull/71129)). +- `JustifyContentControl`: Include Space around and Space evenly in the default controls ([#71129](https://github.com/WordPress/gutenberg/pull/71129)). ### Enhancements @@ -93,11 +95,6 @@ - `RichTextToolbarButton`: Passing a `name` prop will no longer render a dedicated Fill unless that name corresponds to a known core toolbar format ([#85843](https://github.com/WordPress/gutenberg/pull/85843)). -### New Features - -- Flex layout: Add Space around and Space evenly justification options, using a select control with icons and labels in the Layout panel ([#71129](https://github.com/WordPress/gutenberg/pull/71129)). -- `JustifyContentControl`: Include Space around and Space evenly in the default controls ([#71129](https://github.com/WordPress/gutenberg/pull/71129)). - ### Enhancements - Migrate `BackgroundClipControl` to `@wordpress/ui` `SelectControl`. Internal markup and CSS classes have changed; custom CSS overrides may need updates ([#86046](https://github.com/WordPress/gutenberg/pull/86046)). diff --git a/packages/block-editor/src/components/justify-content-control/test/index.jsdom.test.ts b/packages/block-editor/src/components/justify-content-control/test/index.jsdom.test.ts deleted file mode 100644 index 8cfdaf74eeff8d..00000000000000 --- a/packages/block-editor/src/components/justify-content-control/test/index.jsdom.test.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { expect, test, vi } from 'vitest'; -import { render, screen } from '@testing-library/react'; -import userEvent from '@testing-library/user-event'; -import { createElement } from '@wordpress/element'; -import JustifyContentUI from '../ui'; - -test( 'lists every justification option by default', async () => { - const user = userEvent.setup(); - const { unmount } = render( - createElement( JustifyContentUI, { - value: 'left', - onChange: vi.fn(), - } ) - ); - - await user.click( - screen.getByRole( 'button', { name: 'Change items justification' } ) - ); - - expect( - screen.getAllByRole( 'menuitem' ).map( ( item ) => item.textContent ) - ).toEqual( [ - 'Left', - 'Center', - 'Right', - 'Space between', - 'Space around', - 'Space evenly', - ] ); - - // Cancel delayed popover positioning effects. - unmount(); -} ); diff --git a/packages/block-editor/src/layouts/flex.tsx b/packages/block-editor/src/layouts/flex.tsx index 86790c8429716d..130645eb7d5638 100644 --- a/packages/block-editor/src/layouts/flex.tsx +++ b/packages/block-editor/src/layouts/flex.tsx @@ -610,7 +610,7 @@ function FlexLayoutJustifyContentControl( { value={ selectedOption } isItemEqualToValue={ ( item, value ) => item.value === value.value } onValueChange={ ( selectedItem ) => { - if ( selectedItem && selectedItem.value !== null ) { + if ( selectedItem ) { onJustificationChange( selectedItem.value ); } } } From 2d96d7df3da76d2c2bc3e2499b625949db8542e2 Mon Sep 17 00:00:00 2001 From: Sukhendu Sekhar Guria Date: Mon, 30 Nov 2026 13:04:32 +0530 Subject: [PATCH 14/19] fix: restore null check in justification change handler --- packages/block-editor/src/layouts/flex.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-editor/src/layouts/flex.tsx b/packages/block-editor/src/layouts/flex.tsx index 130645eb7d5638..86790c8429716d 100644 --- a/packages/block-editor/src/layouts/flex.tsx +++ b/packages/block-editor/src/layouts/flex.tsx @@ -610,7 +610,7 @@ function FlexLayoutJustifyContentControl( { value={ selectedOption } isItemEqualToValue={ ( item, value ) => item.value === value.value } onValueChange={ ( selectedItem ) => { - if ( selectedItem ) { + if ( selectedItem && selectedItem.value !== null ) { onJustificationChange( selectedItem.value ); } } } From 2a97734dfa354e2ebde694d512631e0f9fd69a2d Mon Sep 17 00:00:00 2001 From: Sukhendu Sekhar Guria Date: Wed, 2 Dec 2026 10:59:21 +0530 Subject: [PATCH 15/19] fix: keep justification when flex orientation changes --- packages/block-editor/src/layouts/flex.tsx | 2 + .../src/layouts/test/flex.jsdom.test.tsx | 53 +++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/packages/block-editor/src/layouts/flex.tsx b/packages/block-editor/src/layouts/flex.tsx index 86790c8429716d..65c6f949478575 100644 --- a/packages/block-editor/src/layouts/flex.tsx +++ b/packages/block-editor/src/layouts/flex.tsx @@ -604,6 +604,8 @@ function FlexLayoutJustifyContentControl( { return ( { ).toHaveTextContent( 'Left' ); } ); + it( 'should not change the justification when the orientation changes', async () => { + const user = userEvent.setup(); + const onChange = vi.fn(); + const renderWithLayout = ( layout: Record< string, string > ) => ( + + + + ); + const { rerender } = render( + renderWithLayout( { + orientation: 'vertical', + justifyContent: 'center', + } ) + ); + await user.click( + await screen.findByRole( 'combobox', { name: 'Justification' } ) + ); + await user.click( + await screen.findByRole( 'option', { name: 'Stretch items' } ) + ); + expect( onChange ).toHaveBeenCalledWith( { + orientation: 'vertical', + justifyContent: 'stretch', + } ); + onChange.mockClear(); + + rerender( + renderWithLayout( { + orientation: 'vertical', + justifyContent: 'stretch', + } ) + ); + rerender( + renderWithLayout( { + orientation: 'horizontal', + justifyContent: 'stretch', + } ) + ); + + expect( + await screen.findByRole( 'combobox', { name: 'Justification' } ) + ).toHaveTextContent( 'Left' ); + expect( onChange ).not.toHaveBeenCalled(); + } ); + it( 'should not render the wrap toggle by default', async () => { renderInspectorControls(); await screen.findByRole( 'combobox', { name: 'Justification' } ); From 686f33cdfa32822cd47d6484c17b7cd431bed162 Mon Sep 17 00:00:00 2001 From: Sukhendu Sekhar Guria Date: Wed, 2 Dec 2026 18:58:25 +0530 Subject: [PATCH 16/19] fix: rename Stretch label, align Constrained labels, update nav PHPDoc --- backport-changelog/{7.2 => 7.3}/13710.md | 0 .../src/components/justify-content-control/ui.tsx | 2 +- packages/block-editor/src/layouts/constrained.tsx | 8 ++++---- packages/block-editor/src/layouts/flex.tsx | 2 +- .../block-editor/src/layouts/test/flex.jsdom.test.tsx | 2 +- packages/block-library/src/navigation/index.php | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) rename backport-changelog/{7.2 => 7.3}/13710.md (100%) diff --git a/backport-changelog/7.2/13710.md b/backport-changelog/7.3/13710.md similarity index 100% rename from backport-changelog/7.2/13710.md rename to backport-changelog/7.3/13710.md diff --git a/packages/block-editor/src/components/justify-content-control/ui.tsx b/packages/block-editor/src/components/justify-content-control/ui.tsx index c33113057f9ee0..039a3b5713a168 100644 --- a/packages/block-editor/src/components/justify-content-control/ui.tsx +++ b/packages/block-editor/src/components/justify-content-control/ui.tsx @@ -95,7 +95,7 @@ function JustifyContentUI( { { name: 'stretch', icon: justifyStretch, - title: __( 'Stretch items' ), + title: _x( 'Stretch', 'Flex layout justification option' ), isActive: 'stretch' === value, onClick: () => handleClick( 'stretch' ), }, diff --git a/packages/block-editor/src/layouts/constrained.tsx b/packages/block-editor/src/layouts/constrained.tsx index 4a60e50eeced68..1c8c79c3bb8cdc 100644 --- a/packages/block-editor/src/layouts/constrained.tsx +++ b/packages/block-editor/src/layouts/constrained.tsx @@ -6,7 +6,7 @@ import { __experimentalInputControlPrefixWrapper as InputControlPrefixWrapper, __experimentalToolsPanelItem as ToolsPanelItem, } from '@wordpress/components'; -import { __ } from '@wordpress/i18n'; +import { __, _x } from '@wordpress/i18n'; import { Icon, alignNone, @@ -71,17 +71,17 @@ export default { { value: 'left', icon: justifyLeft, - label: __( 'Justify items left' ), + label: _x( 'Left', 'Flex layout justification option' ), }, { value: 'center', icon: justifyCenter, - label: __( 'Justify items center' ), + label: _x( 'Center', 'Flex layout justification option' ), }, { value: 'right', icon: justifyRight, - label: __( 'Justify items right' ), + label: _x( 'Right', 'Flex layout justification option' ), }, ]; const [ availableUnits ] = useSettings( 'spacing.units' ); diff --git a/packages/block-editor/src/layouts/flex.tsx b/packages/block-editor/src/layouts/flex.tsx index 65c6f949478575..b742c26a5ded61 100644 --- a/packages/block-editor/src/layouts/flex.tsx +++ b/packages/block-editor/src/layouts/flex.tsx @@ -592,7 +592,7 @@ function FlexLayoutJustifyContentControl( { } else { justificationOptions.push( { value: 'stretch', - label: __( 'Stretch items' ), + label: _x( 'Stretch', 'Flex layout justification option' ), icon: justifyStretch, } ); } diff --git a/packages/block-editor/src/layouts/test/flex.jsdom.test.tsx b/packages/block-editor/src/layouts/test/flex.jsdom.test.tsx index 4e19a50d6c0a88..4ff6f94a2bb3aa 100644 --- a/packages/block-editor/src/layouts/test/flex.jsdom.test.tsx +++ b/packages/block-editor/src/layouts/test/flex.jsdom.test.tsx @@ -140,7 +140,7 @@ describe( 'FlexLayoutInspectorControls', () => { await screen.findByRole( 'combobox', { name: 'Justification' } ) ); await user.click( - await screen.findByRole( 'option', { name: 'Stretch items' } ) + await screen.findByRole( 'option', { name: 'Stretch' } ) ); expect( onChange ).toHaveBeenCalledWith( { orientation: 'vertical', diff --git a/packages/block-library/src/navigation/index.php b/packages/block-library/src/navigation/index.php index 0660b112813e20..07726fbaf940d9 100644 --- a/packages/block-library/src/navigation/index.php +++ b/packages/block-library/src/navigation/index.php @@ -49,10 +49,10 @@ function block_core_navigation_get_submenu_visibility( $attributes ) { * @return array Navigation layout custom property declarations. * * @phpstan-return array{ - * '--navigation-layout-justification-setting': 'flex-start'|'center'|'flex-end'|'space-between', + * '--navigation-layout-justification-setting': 'flex-start'|'center'|'flex-end'|'space-between'|'space-around'|'space-evenly', * '--navigation-layout-direction': 'column'|'row', * '--navigation-layout-wrap': 'nowrap'|'wrap', - * '--navigation-layout-justify': 'initial'|'flex-start'|'center'|'flex-end'|'space-between', + * '--navigation-layout-justify': 'initial'|'flex-start'|'center'|'flex-end'|'space-between'|'space-around'|'space-evenly', * '--navigation-layout-align': 'flex-start'|'center'|'flex-end', * } */ From f21db59cd74192f7524c825735d35f120f689d3a Mon Sep 17 00:00:00 2001 From: Sukhendu Sekhar Guria Date: Wed, 2 Dec 2026 19:01:32 +0530 Subject: [PATCH 17/19] fix: use vi.mocked in navigation layout custom properties test --- .../edit/test/layout-custom-properties.jsdom.test.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/block-library/src/navigation/edit/test/layout-custom-properties.jsdom.test.ts b/packages/block-library/src/navigation/edit/test/layout-custom-properties.jsdom.test.ts index 1a1ceee15afc79..ee9237a1886f18 100644 --- a/packages/block-library/src/navigation/edit/test/layout-custom-properties.jsdom.test.ts +++ b/packages/block-library/src/navigation/edit/test/layout-custom-properties.jsdom.test.ts @@ -96,7 +96,11 @@ describe( 'Navigation layout custom properties', () => { } ) ); - const { css } = useStyleOverride.mock.calls.at( -1 )[ 0 ]; + const { css } = vi + .mocked( useStyleOverride ) + .mock.calls.at( -1 )![ 0 ] as { + css: string; + }; expect( css ).toContain( `--navigation-layout-justification-setting: ${ justify };` ); From 1167f9fd56d1cdd23226c2cbf9aca122ca1da85f Mon Sep 17 00:00:00 2001 From: Sukhendu Sekhar Guria Date: Thu, 3 Dec 2026 09:07:39 +0530 Subject: [PATCH 18/19] fix: keep the original JustifyContentControl default controls --- packages/block-editor/CHANGELOG.md | 1 - .../src/components/justify-content-control/README.md | 2 +- .../src/components/justify-content-control/ui.tsx | 9 +-------- 3 files changed, 2 insertions(+), 10 deletions(-) diff --git a/packages/block-editor/CHANGELOG.md b/packages/block-editor/CHANGELOG.md index 996bc4d5d47bc7..d4734a6f51c17f 100644 --- a/packages/block-editor/CHANGELOG.md +++ b/packages/block-editor/CHANGELOG.md @@ -9,7 +9,6 @@ - Add an Offset control with X and Y axes to the Transform panel, for the `transform.translate` block support ([#86282](https://github.com/WordPress/gutenberg/pull/86282)). - Add a Scale control to the Transform panel, for the `transform.scale` block support ([#86727](https://github.com/WordPress/gutenberg/pull/86727)). - Flex layout: Add Space around and Space evenly justification options, using a select control with icons and labels in the Layout panel ([#71129](https://github.com/WordPress/gutenberg/pull/71129)). -- `JustifyContentControl`: Include Space around and Space evenly in the default controls ([#71129](https://github.com/WordPress/gutenberg/pull/71129)). ### Enhancements diff --git a/packages/block-editor/src/components/justify-content-control/README.md b/packages/block-editor/src/components/justify-content-control/README.md index 041f0590b032fa..f6619063753624 100644 --- a/packages/block-editor/src/components/justify-content-control/README.md +++ b/packages/block-editor/src/components/justify-content-control/README.md @@ -43,7 +43,7 @@ _Note:_ In this example that we render `JustifyContentControl` as a child of the #### `allowedControls` - **Type:** `string[]` -- **Default:** `[ 'left', 'center', 'right', 'space-between', 'space-around', 'space-evenly' ]` +- **Default:** `[ 'left', 'center', 'right', 'space-between' ]` An array of strings for what controls to show, by default it shows all. diff --git a/packages/block-editor/src/components/justify-content-control/ui.tsx b/packages/block-editor/src/components/justify-content-control/ui.tsx index 039a3b5713a168..ab40a59eb0ec0b 100644 --- a/packages/block-editor/src/components/justify-content-control/ui.tsx +++ b/packages/block-editor/src/components/justify-content-control/ui.tsx @@ -23,14 +23,7 @@ const icons = { }; function JustifyContentUI( { - allowedControls = [ - 'left', - 'center', - 'right', - 'space-between', - 'space-around', - 'space-evenly', - ], + allowedControls = [ 'left', 'center', 'right', 'space-between' ], isCollapsed = true, onChange, value, From 294b094cb3c92b17db9ab3ba25eb4f404f16565e Mon Sep 17 00:00:00 2001 From: Sukhendu Sekhar Guria Date: Thu, 3 Dec 2026 13:20:42 +0530 Subject: [PATCH 19/19] docs: clarify JustifyContentControl allowedControls and changelog --- packages/block-editor/CHANGELOG.md | 1 + .../src/components/justify-content-control/README.md | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/block-editor/CHANGELOG.md b/packages/block-editor/CHANGELOG.md index da11adc2943598..46fd6c26a6c9f8 100644 --- a/packages/block-editor/CHANGELOG.md +++ b/packages/block-editor/CHANGELOG.md @@ -5,6 +5,7 @@ ### New Features - Flex layout: Add Space around and Space evenly justification options, using a select control with icons and labels in the Layout panel ([#71129](https://github.com/WordPress/gutenberg/pull/71129)). +- `JustifyContentControl`: Support `space-around` and `space-evenly` through `allowedControls` ([#71129](https://github.com/WordPress/gutenberg/pull/71129)). ### Bug Fixes diff --git a/packages/block-editor/src/components/justify-content-control/README.md b/packages/block-editor/src/components/justify-content-control/README.md index f6619063753624..e5c325e5c6cbaa 100644 --- a/packages/block-editor/src/components/justify-content-control/README.md +++ b/packages/block-editor/src/components/justify-content-control/README.md @@ -45,7 +45,7 @@ _Note:_ In this example that we render `JustifyContentControl` as a child of the - **Type:** `string[]` - **Default:** `[ 'left', 'center', 'right', 'space-between' ]` -An array of strings for what controls to show, by default it shows all. +An array of strings for what controls to show. Pass `space-around`, `space-evenly`, or `stretch` to show those controls, which are not shown by default. #### `onChange`