Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use correct layout type to display controls. #59979

Merged
merged 1 commit into from
Mar 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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