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

Layout: only show inherit toggle in default layout (hide on Row block variation) #39665

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion packages/block-editor/src/hooks/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ function LayoutPanel( { setAttributes, attributes, name: blockName } ) {
return null;
}

// Only show the inherit toggle if it's supported,
// a default theme layout is set (e.g. one that provides `contentSize` and/or `wideSize` values),
// and that the default / flow layout type is in use, as this is the only one that supports inheritance.
const showInheritToggle = !! (
allowInheriting &&
!! defaultThemeLayout &&
( ! layout?.type || layout?.type === 'default' || layout?.inherit )
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: I've added layout?.inherit to this conditional so that any blocks that are currently in the weird state of having a flex type but inheriting from the default layout can switch off inherit via the UI.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make the toggle disappear if they do toggle it off in this state or is that too confusing for the user?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking a look @glendaviesnz — currently, toggling inherit also switches the type to default since the layout attribute is cleared out of anything but the inherit property (so the toggle would still be visible). Given how the toggle works, I'm hoping we don't actually have anyone in that weird circumstance of inherit being set to true and the type being set to something other than default.

I mostly added the layout?.inherit to be cautious just in case something was set manually to that state, but I'm not sure if it ever would have been possible to get into that state via the UI, so it's possibly an artificial example 🤔

);

const usedLayout = layout || defaultBlockLayout || {};
const { inherit = false, type = 'default' } = usedLayout;
/**
Expand All @@ -77,7 +86,7 @@ function LayoutPanel( { setAttributes, attributes, name: blockName } ) {
<>
<InspectorControls>
<PanelBody title={ __( 'Layout' ) }>
{ allowInheriting && !! defaultThemeLayout && (
{ showInheritToggle && (
<ToggleControl
label={ __( 'Inherit default layout' ) }
checked={ !! inherit }
Expand Down