diff --git a/backport-changelog/7.3/13710.md b/backport-changelog/7.3/13710.md new file mode 100644 index 00000000000000..248426e2ffc9ed --- /dev/null +++ b/backport-changelog/7.3/13710.md @@ -0,0 +1,3 @@ +https://github.com/WordPress/wordpress-develop/pull/13710 + +* https://github.com/WordPress/gutenberg/pull/71129 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/lib/block-supports/layout.php b/lib/block-supports/layout.php index cbe53095afc476..4a4188ecdccd5a 100644 --- a/lib/block-supports/layout.php +++ b/lib/block-supports/layout.php @@ -740,7 +740,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-editor/CHANGELOG.md b/packages/block-editor/CHANGELOG.md index dd5116523d8c43..46fd6c26a6c9f8 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`: Support `space-around` and `space-evenly` through `allowedControls` ([#71129](https://github.com/WordPress/gutenberg/pull/71129)). + ### Bug Fixes - List View: Pasting a file without upload permissions no longer replaces the focused block ([#87852](https://github.com/WordPress/gutenberg/pull/87852)). 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..e5c325e5c6cbaa 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. @@ -43,14 +45,14 @@ _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` - **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/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/types.ts b/packages/block-editor/src/components/justify-content-control/types.ts index 7a66833a9a1abb..2a50870a505a18 100644 --- a/packages/block-editor/src/components/justify-content-control/types.ts +++ b/packages/block-editor/src/components/justify-content-control/types.ts @@ -5,7 +5,13 @@ import type { Dropdown } from '@wordpress/components'; * A justification of the items in a block. */ export type JustifyContentValue = - 'left' | 'center' | 'right' | 'space-between' | 'stretch'; + | 'left' + | 'center' + | 'right' + | 'space-between' + | 'space-around' + | 'space-evenly' + | 'stretch'; /** * Props of `JustifyContentControl` and `JustifyToolbar`. 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 1237e961e6f680..ab40a59eb0ec0b 100644 --- a/packages/block-editor/src/components/justify-content-control/ui.tsx +++ b/packages/block-editor/src/components/justify-content-control/ui.tsx @@ -5,9 +5,11 @@ import { justifyCenter, justifyRight, justifySpaceBetween, + justifySpaceAround, + justifySpaceEvenly, justifyStretch, } from '@wordpress/icons'; -import { __ } from '@wordpress/i18n'; +import { __, _x } from '@wordpress/i18n'; import type { JustifyContentUIProps, JustifyContentValue } from './types'; const icons = { @@ -15,6 +17,8 @@ const icons = { center: justifyCenter, right: justifyRight, 'space-between': justifySpaceBetween, + 'space-around': justifySpaceAround, + 'space-evenly': justifySpaceEvenly, stretch: justifyStretch, }; @@ -42,35 +46,49 @@ 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' ), + isActive: 'space-around' === value, + onClick: () => handleClick( 'space-around' ), + }, + { + name: 'space-evenly', + icon: justifySpaceEvenly, + title: __( 'Space evenly' ), + isActive: 'space-evenly' === value, + onClick: () => handleClick( 'space-evenly' ), + }, { 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/hooks/layout.scss b/packages/block-editor/src/hooks/layout.scss index 8cfa9b57e8e4fb..f39cb4514ef41b 100644 --- a/packages/block-editor/src/hooks/layout.scss +++ b/packages/block-editor/src/hooks/layout.scss @@ -16,6 +16,18 @@ .layout-block-support-panel { .block-editor-hooks__flex-layout-controls { grid-column: 1 / -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/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 237e79a952db70..b742c26a5ded61 100644 --- a/packages/block-editor/src/layouts/flex.tsx +++ b/packages/block-editor/src/layouts/flex.tsx @@ -1,10 +1,12 @@ -import type { ReactElement } from 'react'; +import type { ComponentProps, ReactElement } from 'react'; import { __, _x } from '@wordpress/i18n'; import { justifyLeft, justifyCenter, justifyRight, justifySpaceBetween, + justifySpaceAround, + justifySpaceEvenly, justifyStretch, justifyTop, justifyCenterVertical, @@ -21,6 +23,7 @@ import { __experimentalToggleGroupControlOptionIcon as ToggleGroupControlOptionIcon, __experimentalToolsPanelItem as ToolsPanelItem, } from '@wordpress/components'; +import { Icon, SelectControl, Stack } from '@wordpress/ui'; import { appendSelectors, getBlockGapCSS } from './utils'; import { getGapCSSValue, getGapBoxControlValueFromStyle } from '../hooks/gap'; import { getSpacingPresetCssVar } from '../components/spacing-sizes-control/utils'; @@ -49,6 +52,8 @@ const justifyContentMap: Record< string, string > = { right: 'flex-end', center: 'center', 'space-between': 'space-between', + 'space-around': 'space-around', + 'space-evenly': 'space-evenly', }; // Used with the vertical (column) flex orientation. @@ -202,6 +207,7 @@ export default { > { allowJustification && ( [ 'icon' ]; }[] = [ { value: 'left', + label: _x( 'Left', 'Flex layout justification option' ), icon: justifyLeft, - label: __( 'Justify items left' ), }, { value: 'center', + label: _x( 'Center', 'Flex layout justification option' ), icon: justifyCenter, - label: __( 'Justify items center' ), }, { value: 'right', + label: _x( 'Right', 'Flex layout justification option' ), icon: justifyRight, - label: __( 'Justify items right' ), }, ]; if ( orientation === 'horizontal' ) { - justificationOptions.push( { - value: 'space-between', - icon: justifySpaceBetween, - label: __( 'Space between items' ), - } ); + justificationOptions.push( + { + value: 'space-between', + label: __( 'Space between' ), + icon: justifySpaceBetween, + }, + { + value: 'space-around', + label: __( 'Space around' ), + icon: justifySpaceAround, + }, + { + value: 'space-evenly', + label: __( 'Space evenly' ), + icon: justifySpaceEvenly, + } + ); } else { justificationOptions.push( { value: 'stretch', + label: _x( 'Stretch', 'Flex layout justification option' ), icon: justifyStretch, - label: __( 'Stretch items' ), } ); } + const selectedOption = + justificationOptions.find( + ( option ) => option.value === justifyContent + ) ?? justificationOptions[ 0 ]; + return ( - item.value === value.value } + onValueChange={ ( selectedItem ) => { + if ( selectedItem && selectedItem.value !== null ) { + onJustificationChange( selectedItem.value ); + } + } } > - { justificationOptions.map( ( { value, icon, label } ) => { - return ( - - ); - } ) } - + { justificationOptions.map( ( option ) => ( + + + + + { option.label } + + + + ) ) } + ); } @@ -641,7 +677,11 @@ function OrientationControl( { layout, onChange }: LayoutControlProps ) { if ( verticalAlignment === 'stretch' ) { newVerticalAlignment = 'top'; } - if ( justifyContent === 'space-between' ) { + if ( + justifyContent === 'space-between' || + justifyContent === 'space-around' || + justifyContent === 'space-evenly' + ) { newJustification = 'left'; } } 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 a6b5ba838c0974..4ff6f94a2bb3aa 100644 --- a/packages/block-editor/src/layouts/test/flex.jsdom.test.tsx +++ b/packages/block-editor/src/layouts/test/flex.jsdom.test.tsx @@ -87,9 +87,89 @@ describe( 'getLayoutStyle', () => { } ); 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 fall back to the first option when the justification is not available for the orientation', async () => { + renderInspectorControls( { + layout: { orientation: 'horizontal', justifyContent: 'stretch' }, + } ); + + expect( + await screen.findByRole( 'combobox', { name: 'Justification' } ) + ).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' } ) + ); + 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( 'radio', { name: 'Justify items left' } ); + await screen.findByRole( 'combobox', { name: 'Justification' } ); expect( screen.queryByRole( 'checkbox', { 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 1e2773320310cb..e40da538a2d022 100644 --- a/packages/block-library/src/common.scss +++ b/packages/block-library/src/common.scss @@ -123,6 +123,14 @@ $fit-content: ".has-rotation:not(.alignwide):not(.alignfull):not(.is-layout-flex 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%); diff --git a/packages/block-library/src/navigation/edit/index.tsx b/packages/block-library/src/navigation/edit/index.tsx index ba2d9b1b3d325e..e8c8a5793b0851 100644 --- a/packages/block-library/src/navigation/edit/index.tsx +++ b/packages/block-library/src/navigation/edit/index.tsx @@ -662,6 +662,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.ts b/packages/block-library/src/navigation/edit/test/layout-custom-properties.jsdom.test.ts index e9b0a3e54c81f1..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 @@ -76,6 +76,40 @@ describe( 'Navigation layout custom properties', () => { ); } ); + 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 } = vi + .mocked( useStyleOverride ) + .mock.calls.at( -1 )![ 0 ] as { + css: string; + }; + 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( () => diff --git a/packages/block-library/src/navigation/edit/use-layout-custom-properties.ts b/packages/block-library/src/navigation/edit/use-layout-custom-properties.ts index cb43b70bde7b51..e16a736ec21a59 100644 --- a/packages/block-library/src/navigation/edit/use-layout-custom-properties.ts +++ b/packages/block-library/src/navigation/edit/use-layout-custom-properties.ts @@ -10,6 +10,8 @@ const JUSTIFICATION_VALUES: Record< string, string > = { 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 22ce7fa11187bc..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', * } */ @@ -62,6 +62,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 = $layout['justifyContent'] ?? 'left'; if ( ! is_string( $justify_content ) || ! isset( $justification_values[ $justify_content ] ) ) { @@ -637,6 +639,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 9b1edf7c15f5d6..5d629bd69ad0ee 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. @@ -458,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/phpunit/block-supports/layout-test.php b/phpunit/block-supports/layout-test.php index f465b793683250..a3c4c24d8c690e 100644 --- a/phpunit/block-supports/layout-test.php +++ b/phpunit/block-supports/layout-test.php @@ -388,6 +388,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/render-block-navigation-test.php b/phpunit/blocks/render-block-navigation-test.php index f19a1f23742e81..b95feb16a03164 100644 --- a/phpunit/blocks/render-block-navigation-test.php +++ b/phpunit/blocks/render-block-navigation-test.php @@ -328,6 +328,49 @@ public function test_get_layout_custom_property_declarations() { ); } + /** + * Test that horizontal justification values are mapped to Navigation custom properties. + * + * @dataProvider data_horizontal_justification_values + * + * @covers ::gutenberg_block_core_navigation_get_layout_custom_property_declarations + * + * @param string $justify_content Justification value. + * @param string $justify Expected CSS value. + */ + public function test_get_horizontal_layout_custom_property_declarations( $justify_content, $justify ) { + $actual = gutenberg_block_core_navigation_get_layout_custom_property_declarations( + array( 'justifyContent' => $justify_content ) + ); + + $this->assertSame( + array( + '--navigation-layout-justification-setting' => $justify, + '--navigation-layout-direction' => 'row', + '--navigation-layout-wrap' => 'wrap', + '--navigation-layout-justify' => $justify, + '--navigation-layout-align' => 'center', + ), + $actual + ); + } + + /** + * Data provider for horizontal Navigation justification values. + * + * @return array + */ + public function data_horizontal_justification_values() { + return array( + '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' ), + ); + } + /** * Test responsive layout styles and classes on local Navigation containers. * diff --git a/schemas/json/block.json b/schemas/json/block.json index 9f925283c331d4..bbffbc9c2d7df4 100644 --- a/schemas/json/block.json +++ b/schemas/json/block.json @@ -452,6 +452,8 @@ "right", "center", "space-between", + "space-around", + "space-evenly", "left", "stretch" ]