Skip to content

Commit f8426c2

Browse files
Editor: Fix spacing property generation in flow layout type.
Fixes a bug of invalid CSS value when applying block spacing to a block as reported in [WordPress/gutenberg#44435 Gutenberg issue 44435]. Adds logic to convert preset values (i.e. `$gap_value`) into valid CSS custom properties for the flow ('default') layout type. See the original fix in [WordPress#3324 Gutenberg PR 3324]. Also adds a test dataset that fails before the bugfix and passes after the bugix. Follow-up to [54274]. Props ndiego, isabel_brison, ramonopoly, andrewserong, hellofromTonya. See #56467. git-svn-id: https://develop.svn.wordpress.org/trunk@54311 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 599622c commit f8426c2

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/wp-includes/block-supports/layout.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ function wp_get_layout_style( $selector, $layout, $has_block_gap_support = false
5656
$gap_value = isset( $gap_value['top'] ) ? $gap_value['top'] : null;
5757
}
5858
if ( null !== $gap_value && ! $should_skip_gap_serialization ) {
59+
// Get spacing CSS variable from preset value if provided.
60+
if ( is_string( $gap_value ) && str_contains( $gap_value, 'var:preset|spacing|' ) ) {
61+
$index_to_splice = strrpos( $gap_value, '|' ) + 1;
62+
$slug = _wp_to_kebab_case( substr( $gap_value, $index_to_splice ) );
63+
$gap_value = "var(--wp--preset--spacing--$slug)";
64+
}
65+
5966
array_push(
6067
$layout_styles,
6168
array(

tests/phpunit/tests/block-supports/wpGetLayoutStyle.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,20 @@ public function data_wp_get_layout_style() {
248248
),
249249
'expected_output' => '.wp-layout{flex-wrap:nowrap;flex-direction:column;align-items:flex-start;}',
250250
),
251+
'default layout with blockGap to verify converting gap value into valid CSS' => array(
252+
'args' => array(
253+
'selector' => '.wp-block-group.wp-container-6',
254+
'layout' => array(
255+
'type' => 'default',
256+
),
257+
'has_block_gap_support' => true,
258+
'gap_value' => 'var:preset|spacing|70',
259+
'block_spacing' => array(
260+
'blockGap' => 'var(--wp--preset--spacing--70)',
261+
),
262+
),
263+
'expected_output' => '.wp-block-group.wp-container-6 > *{margin-block-start:0;margin-block-end:0;}.wp-block-group.wp-container-6.wp-block-group.wp-container-6 > * + *{margin-block-start:var(--wp--preset--spacing--70);margin-block-end:0;}',
264+
),
251265
);
252266
}
253267
}

0 commit comments

Comments
 (0)