Skip to content

Commit

Permalink
Layout child fixed size should not be fixed by default and should alw…
Browse files Browse the repository at this point in the history
…ays have a value set (WordPress#46139)

* Change behaviour of fixed child size to not be fixed by default

* Fix boo-boo

* Remove unshrink control

* Determine fixed size automatically

* Revert "Determine fixed size automatically"

This reverts commit 2ec5ac7.
  • Loading branch information
tellthemachines authored and mpkelly committed Dec 7, 2022
1 parent ee831f4 commit f4f3f2d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
5 changes: 2 additions & 3 deletions lib/block-supports/layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,8 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) {
$child_layout_styles[] = array(
'selector' => ".$container_content_class",
'declarations' => array(
'flex-shrink' => '0',
'flex-basis' => $block['attrs']['style']['layout']['flexSize'],
'box-sizing' => 'border-box',
'flex-basis' => $block['attrs']['style']['layout']['flexSize'],
'box-sizing' => 'border-box',
),
);
} elseif ( 'fill' === $block['attrs']['style']['layout']['selfStretch'] ) {
Expand Down
15 changes: 15 additions & 0 deletions packages/block-editor/src/hooks/child-layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
__experimentalUnitControl as UnitControl,
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { useEffect } from '@wordpress/element';

/**
* Internal dependencies
Expand Down Expand Up @@ -43,6 +44,20 @@ export function ChildLayoutEdit( {
const { layout: childLayout = {} } = style;
const { selfStretch, flexSize } = childLayout;

useEffect( () => {
if ( selfStretch === 'fixed' && ! flexSize ) {
setAttributes( {
style: {
...style,
layout: {
...childLayout,
selfStretch: 'fit',
},
},
} );
}
}, [] );

return (
<>
<ToggleGroupControl
Expand Down
1 change: 0 additions & 1 deletion packages/block-editor/src/hooks/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,6 @@ export const withChildLayoutStyles = createHigherOrderComponent(

if ( selfStretch === 'fixed' && flexSize ) {
css += `${ selector } {
flex-shrink: 0;
flex-basis: ${ flexSize };
box-sizing: border-box;
}`;
Expand Down

0 comments on commit f4f3f2d

Please sign in to comment.