Skip to content

Commit

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

Co-authored-by: aaronrobertshaw <[email protected]>
Co-authored-by: andrewserong <[email protected]>
Co-authored-by: t-hamano <[email protected]>
Co-authored-by: ramonjd <[email protected]>
Co-authored-by: getdave <[email protected]>
Co-authored-by: carolinan <[email protected]>
Co-authored-by: ndiego <[email protected]>
Co-authored-by: juanfra <[email protected]>
Co-authored-by: ltrihan <[email protected]>
  • 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

0 comments on commit 4651b82

Please sign in to comment.