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

[WIP] Group: Try setting inherit to true if the block is empty and hasn't set an inherit value yet #42876

Closed
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
16 changes: 15 additions & 1 deletion packages/block-library/src/group/edit.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/**
* WordPress dependencies
*/
import { useSelect } from '@wordpress/data';
import { useSelect, useDispatch } from '@wordpress/data';
import { useEffect } from '@wordpress/element';
import {
InnerBlocks,
useBlockProps,
Expand Down Expand Up @@ -67,6 +68,19 @@ function GroupEdit( { attributes, setAttributes, clientId } ) {
}
);

const { __unstableMarkNextChangeAsNotPersistent } =
useDispatch( blockEditorStore );
const { inherit } = layout;
useEffect( () => {
// If a block has not yet set the `inherit` value to either `true` or `false`,
// and it doesn't have any inner blocks, then set it to the desired default value.
// This ensures that newly inserted blocks are set to use the root/global content sizes.
if ( inherit === undefined && ! hasInnerBlocks ) {
__unstableMarkNextChangeAsNotPersistent();
setAttributes( { layout: { inherit: true } } );
}
}, [ hasInnerBlocks, inherit ] );

return (
<>
<InspectorControls __experimentalGroup="advanced">
Expand Down