Skip to content

Commit

Permalink
Block Gap: Fix block spacing control for axial gap supported blocks (#…
Browse files Browse the repository at this point in the history
…66783)

Co-authored-by: aaronrobertshaw <aaronrobertshaw@git.wordpress.org>
Co-authored-by: andrewserong <andrewserong@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>
Co-authored-by: getdave <get_dave@git.wordpress.org>
Co-authored-by: carolinan <poena@git.wordpress.org>
Co-authored-by: ndiego <ndiego@git.wordpress.org>
Co-authored-by: juanfra <juanfra@git.wordpress.org>
Co-authored-by: ltrihan <ltrihan@git.wordpress.org>
  • Loading branch information
10 people authored Nov 7, 2024
1 parent 3e46fe7 commit 4651b82
Showing 1 changed file with 22 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,24 +147,30 @@ function splitStyleValue( value ) {
return value;
}

function splitGapValue( value ) {
// Check for shorthand value (a string value).
if ( value && typeof value === 'string' ) {
// If the value is a string, treat it as a single side (top) for the spacing controls.
return {
top: value,
};
function splitGapValue( value, isAxialGap ) {
if ( ! value ) {
return value;
}

if ( value ) {
return {
...value,
right: value?.left,
bottom: value?.top,
};
// Check for shorthand value (a string value).
if ( typeof value === 'string' ) {
/*
* Map the string value to appropriate sides for the spacing control depending
* on whether the current block has axial gap support or not.
*
* Note: The axial value pairs must match for the spacing control to display
* the appropriate horizontal/vertical sliders.
*/
return isAxialGap
? { top: value, right: value, bottom: value, left: value }
: { top: value };
}

return value;
return {
...value,
right: value?.left,
bottom: value?.top,
};
}

function DimensionsToolsPanel( {
Expand Down Expand Up @@ -325,13 +331,13 @@ export default function DimensionsPanel( {

// Block Gap
const showGapControl = useHasGap( settings );
const gapValue = decodeValue( inheritedValue?.spacing?.blockGap );
const gapValues = splitGapValue( gapValue );
const gapSides = Array.isArray( settings?.spacing?.blockGap )
? settings?.spacing?.blockGap
: settings?.spacing?.blockGap?.sides;
const isAxialGap =
gapSides && gapSides.some( ( side ) => AXIAL_SIDES.includes( side ) );
const gapValue = decodeValue( inheritedValue?.spacing?.blockGap );
const gapValues = splitGapValue( gapValue, isAxialGap );
const setGapValue = ( newGapValue ) => {
onChange(
setImmutably( value, [ 'spacing', 'blockGap' ], newGapValue )
Expand Down

1 comment on commit 4651b82

@github-actions
Copy link

Choose a reason for hiding this comment

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

Flaky tests detected in 4651b82.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/11714657906
📝 Reported issues:

Please sign in to comment.