From f2e3e186690adfec690d745570a512e3f0186082 Mon Sep 17 00:00:00 2001 From: tellthemachines Date: Wed, 20 Mar 2024 10:33:34 +1100 Subject: [PATCH] Use correct layout type to display controls. (#59979) Co-authored-by: tellthemachines Co-authored-by: ramonjd Co-authored-by: andrewserong --- packages/block-editor/src/hooks/layout.js | 33 ++++++++++++++--------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/packages/block-editor/src/hooks/layout.js b/packages/block-editor/src/hooks/layout.js index 5f9017fce5bf6..d9fa632af32ef 100644 --- a/packages/block-editor/src/hooks/layout.js +++ b/packages/block-editor/src/hooks/layout.js @@ -176,34 +176,43 @@ function LayoutPanelPure( { return null; } + /* + * Try to find the layout type from either the + * block's layout settings or any saved layout config. + */ + const blockSupportAndLayout = { + ...layoutBlockSupport, + ...layout, + }; + const { type, default: { type: defaultType = 'default' } = {} } = + blockSupportAndLayout; + const blockLayoutType = type || defaultType; + // Only show the inherit toggle if it's supported, // and either the default / flow or the constrained layout type is in use, as the toggle switches from one to the other. const showInheritToggle = !! ( allowInheriting && - ( ! layout?.type || - layout?.type === 'default' || - layout?.type === 'constrained' || - layout?.inherit ) + ( ! blockLayoutType || + blockLayoutType === 'default' || + blockLayoutType === 'constrained' || + blockSupportAndLayout.inherit ) ); const usedLayout = layout || defaultBlockLayout || {}; - const { - inherit = false, - type = 'default', - contentSize = null, - } = usedLayout; + const { inherit = false, contentSize = null } = usedLayout; /** * `themeSupportsLayout` is only relevant to the `default/flow` or * `constrained` layouts and it should not be taken into account when other * `layout` types are used. */ if ( - ( type === 'default' || type === 'constrained' ) && + ( blockLayoutType === 'default' || + blockLayoutType === 'constrained' ) && ! themeSupportsLayout ) { return null; } - const layoutType = getLayoutType( type ); + const layoutType = getLayoutType( blockLayoutType ); const constrainedType = getLayoutType( 'constrained' ); const displayControlsForLegacyLayouts = ! usedLayout.type && ( contentSize || inherit ); @@ -256,7 +265,7 @@ function LayoutPanelPure( { { ! inherit && allowSwitching && ( ) }