Skip to content

Commit 8dd0b92

Browse files
MustafabharmalMustafabharmalkarthikeya-ioSwanand01inc2734
authored
Block Editor: Fix blockGap fallback parsing for nested var() values (#77750)
Co-authored-by: Mustafabharmal <mustafabharmal@git.wordpress.org> Co-authored-by: karthikeya-io <karthikeya01@git.wordpress.org> Co-authored-by: Swanand01 <swanandm@git.wordpress.org> Co-authored-by: inc2734 <inc2734@git.wordpress.org>
1 parent e9c833e commit 8dd0b92

2 files changed

Lines changed: 14 additions & 13 deletions

File tree

packages/block-editor/src/layouts/flex.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ import {
2323
* Internal dependencies
2424
*/
2525
import { appendSelectors, getBlockGapCSS } from './utils';
26-
import { getGapCSSValue } from '../hooks/gap';
26+
import { getGapCSSValue, getGapBoxControlValueFromStyle } from '../hooks/gap';
27+
import { getSpacingPresetCssVar } from '../components/spacing-sizes-control/utils';
2728
import {
2829
BlockControls,
2930
JustifyContentControl,
@@ -147,15 +148,12 @@ export default {
147148
// falling back to '0.5em' for backwards compatibility.
148149
let fallbackGapValue = '0.5em';
149150
if ( globalBlockGapValue ) {
150-
// Process the global gap value to handle preset values
151-
const processedGlobalGap = getGapCSSValue(
152-
globalBlockGapValue,
153-
'0.5em'
154-
);
155-
// Use the column gap value (second value if two values exist)
156-
const gapParts = processedGlobalGap.split( ' ' );
151+
const gapBox =
152+
getGapBoxControlValueFromStyle( globalBlockGapValue );
157153
fallbackGapValue =
158-
gapParts.length > 1 ? gapParts[ 1 ] : gapParts[ 0 ];
154+
getSpacingPresetCssVar( gapBox?.left ) ||
155+
getSpacingPresetCssVar( gapBox?.top ) ||
156+
'0.5em';
159157
}
160158

161159
// If a block's block.json skips serialization for spacing or spacing.blockGap,

packages/block-editor/src/layouts/grid.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import { useState } from '@wordpress/element';
2121
* Internal dependencies
2222
*/
2323
import { appendSelectors, getBlockGapCSS } from './utils';
24-
import { getGapCSSValue } from '../hooks/gap';
24+
import { getGapCSSValue, getGapBoxControlValueFromStyle } from '../hooks/gap';
25+
import { getSpacingPresetCssVar } from '../components/spacing-sizes-control/utils';
2526
import { shouldSkipSerialization } from '../hooks/utils';
2627
import { LAYOUT_DEFINITIONS } from './definitions';
2728

@@ -143,10 +144,12 @@ export default {
143144
// If the gap value has both top and left (separated by space), use the left value for horizontal calculations.
144145
let fallbackGapValue = '1.2rem';
145146
if ( globalBlockGapValue ) {
146-
const processedGap = getGapCSSValue( globalBlockGapValue, '0.5em' );
147-
const gapParts = processedGap.split( ' ' );
147+
const gapBox =
148+
getGapBoxControlValueFromStyle( globalBlockGapValue );
148149
fallbackGapValue =
149-
gapParts.length > 1 ? gapParts[ 1 ] : gapParts[ 0 ];
150+
getSpacingPresetCssVar( gapBox?.left ) ||
151+
getSpacingPresetCssVar( gapBox?.top ) ||
152+
'1.2rem';
150153
}
151154

152155
// If a block's block.json skips serialization for spacing or spacing.blockGap,

0 commit comments

Comments
 (0)