Skip to content

Commit

Permalink
Use correct layout type to display controls. (#59979)
Browse files Browse the repository at this point in the history
Co-authored-by: tellthemachines <isabel_brison@git.wordpress.org>
Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>
Co-authored-by: andrewserong <andrewserong@git.wordpress.org>
  • Loading branch information
4 people committed Mar 19, 2024
1 parent 317eb8f commit cef411c
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions packages/block-editor/src/hooks/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -256,7 +265,7 @@ function LayoutPanelPure( {

{ ! inherit && allowSwitching && (
<LayoutTypeSwitcher
type={ type }
type={ blockLayoutType }
onChange={ onChangeType }
/>
) }
Expand Down

0 comments on commit cef411c

Please sign in to comment.