From dea027eac82ca7244eff421642562b2d75918e19 Mon Sep 17 00:00:00 2001 From: Robert Anderson Date: Thu, 18 Jul 2024 06:48:08 +0000 Subject: [PATCH] Block Themes: Fix invalid css for nested fullwidth layouts with zero padding applied In the Layout block support, handle 0 values for padding as 0px in calc() rules. This resolves a bug for nested fullwidth layouts when zero padding is applied. Due to how calc() works, without supplying the unit, the rule will not work, resulting in a horizontal scrollbar. Backports the PHP changes in https://github.com/WordPress/gutenberg/pull/63436. Fixes #61656. Props andrewserong, mukesh27, aaronrobertshaw. git-svn-id: https://develop.svn.wordpress.org/trunk@58750 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/block-supports/layout.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/block-supports/layout.php b/src/wp-includes/block-supports/layout.php index a5b438cd6acaf..d3718930d5062 100644 --- a/src/wp-includes/block-supports/layout.php +++ b/src/wp-includes/block-supports/layout.php @@ -322,14 +322,22 @@ function wp_get_layout_style( $selector, $layout, $has_block_gap_support = false * They're added separately because padding might only be set on one side. */ if ( isset( $block_spacing_values['declarations']['padding-right'] ) ) { - $padding_right = $block_spacing_values['declarations']['padding-right']; + $padding_right = $block_spacing_values['declarations']['padding-right']; + // Add unit if 0. + if ( '0' === $padding_right ) { + $padding_right = '0px'; + } $layout_styles[] = array( 'selector' => "$selector > .alignfull", 'declarations' => array( 'margin-right' => "calc($padding_right * -1)" ), ); } if ( isset( $block_spacing_values['declarations']['padding-left'] ) ) { - $padding_left = $block_spacing_values['declarations']['padding-left']; + $padding_left = $block_spacing_values['declarations']['padding-left']; + // Add unit if 0. + if ( '0' === $padding_left ) { + $padding_left = '0px'; + } $layout_styles[] = array( 'selector' => "$selector > .alignfull", 'declarations' => array( 'margin-left' => "calc($padding_left * -1)" ),