Skip to content

Commit 577dc63

Browse files
richtaborandrewserongfabiankaegy
committed
Layout: Fix invalid css for nested fullwidth layouts with zero padding applied (#63436)
* apply a default unit when set to zero (frontend) * apply a default unit when set to zero (editor) * use 0 as a string * Fix linting issue * Add backport changelog entry --------- Co-authored-by: Andrew Serong <14988353+andrewserong@users.noreply.github.com> Co-authored-by: richtabor <richtabor@git.wordpress.org> Co-authored-by: andrewserong <andrewserong@git.wordpress.org> Co-authored-by: fabiankaegy <fabiankaegy@git.wordpress.org>
1 parent 72df623 commit 577dc63

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

backport-changelog/6.6/7036.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
https://github.com/WordPress/wordpress-develop/pull/7036
2+
3+
* https://github.com/WordPress/gutenberg/pull/63436

lib/block-supports/layout.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,14 +306,22 @@ function gutenberg_get_layout_style( $selector, $layout, $has_block_gap_support
306306
* They're added separately because padding might only be set on one side.
307307
*/
308308
if ( isset( $block_spacing_values['declarations']['padding-right'] ) ) {
309-
$padding_right = $block_spacing_values['declarations']['padding-right'];
309+
$padding_right = $block_spacing_values['declarations']['padding-right'];
310+
// Add unit if 0.
311+
if ( '0' === $padding_right ) {
312+
$padding_right = '0px';
313+
}
310314
$layout_styles[] = array(
311315
'selector' => "$selector > .alignfull",
312316
'declarations' => array( 'margin-right' => "calc($padding_right * -1)" ),
313317
);
314318
}
315319
if ( isset( $block_spacing_values['declarations']['padding-left'] ) ) {
316-
$padding_left = $block_spacing_values['declarations']['padding-left'];
320+
$padding_left = $block_spacing_values['declarations']['padding-left'];
321+
// Add unit if 0.
322+
if ( '0' === $padding_left ) {
323+
$padding_left = '0px';
324+
}
317325
$layout_styles[] = array(
318326
'selector' => "$selector > .alignfull",
319327
'declarations' => array( 'margin-left' => "calc($padding_left * -1)" ),

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,15 +234,23 @@ export default {
234234
const paddingValues = getCSSRules( style );
235235
paddingValues.forEach( ( rule ) => {
236236
if ( rule.key === 'paddingRight' ) {
237+
// Add unit if 0, to avoid calc(0 * -1) which is invalid.
238+
const paddingRightValue =
239+
rule.value === '0' ? '0px' : rule.value;
240+
237241
output += `
238242
${ appendSelectors( selector, '> .alignfull' ) } {
239-
margin-right: calc(${ rule.value } * -1);
243+
margin-right: calc(${ paddingRightValue } * -1);
240244
}
241245
`;
242246
} else if ( rule.key === 'paddingLeft' ) {
247+
// Add unit if 0, to avoid calc(0 * -1) which is invalid.
248+
const paddingLeftValue =
249+
rule.value === '0' ? '0px' : rule.value;
250+
243251
output += `
244252
${ appendSelectors( selector, '> .alignfull' ) } {
245-
margin-left: calc(${ rule.value } * -1);
253+
margin-left: calc(${ paddingLeftValue } * -1);
246254
}
247255
`;
248256
}

0 commit comments

Comments
 (0)