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

Allow the specification of blocks allowed within columns #25778

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from 9 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
3 changes: 3 additions & 0 deletions packages/block-library/src/column/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
"width": {
"type": "string"
},
"allowedBlocks": {
"type": "array"
},
JesserH marked this conversation as resolved.
Show resolved Hide resolved
"templateLock": {
"type": "string"
}
Expand Down
8 changes: 7 additions & 1 deletion packages/block-library/src/column/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ import { __ } from '@wordpress/i18n';
import { CSS_UNITS } from '../columns/utils';

function ColumnEdit( {
attributes: { verticalAlignment, width, templateLock = false },
attributes: {
verticalAlignment,
width,
templateLock = false,
allowedBlocks,
},
setAttributes,
clientId,
} ) {
Expand Down Expand Up @@ -67,6 +72,7 @@ function ColumnEdit( {
} );
const innerBlocksProps = useInnerBlocksProps( blockProps, {
templateLock,
allowedBlocks,
Copy link
Member

Choose a reason for hiding this comment

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

What happens when allowedBlocks is undefined?

renderAppender: hasChildBlocks
? undefined
: InnerBlocks.ButtonBlockAppender,
Expand Down
5 changes: 4 additions & 1 deletion packages/block-library/src/columns/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
"attributes": {
"verticalAlignment": {
"type": "string"
}
},
"allowedChildBlocks": {
"type": "array"
}
},
"supports": {
"anchor": true,
Expand Down
9 changes: 7 additions & 2 deletions packages/block-library/src/columns/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function ColumnsEditContainer( {
updateColumns,
clientId,
} ) {
const { verticalAlignment } = attributes;
const { verticalAlignment, allowedChildBlocks } = attributes;

const { count } = useSelect(
( select ) => {
Expand All @@ -72,6 +72,7 @@ function ColumnsEditContainer( {
} );
const innerBlocksProps = useInnerBlocksProps( blockProps, {
allowedBlocks: ALLOWED_BLOCKS,
allowedChildBlocks,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this line can be removed, allowedChildBlocks isn't a recognized property for inner blocks:
https://github.com/WordPress/gutenberg/blob/master/packages/block-editor/src/components/inner-blocks/README.md#props

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I agree that this line should be removed.

orientation: 'horizontal',
renderAppender: false,
} );
Expand Down Expand Up @@ -142,6 +143,7 @@ const ColumnsEditContainerWrapper = withDispatch(
*/
updateColumns( previousColumns, newColumns ) {
const { clientId } = ownProps;
const { allowedChildBlocks } = ownProps.attributes;
const { replaceInnerBlocks } = dispatch( 'core/block-editor' );
const { getBlocks } = registry.select( 'core/block-editor' );

Expand Down Expand Up @@ -170,14 +172,17 @@ const ColumnsEditContainerWrapper = withDispatch(
...times( newColumns - previousColumns, () => {
return createBlock( 'core/column', {
width: newColumnWidth,
allowedBlocks: allowedChildBlocks,
} );
} ),
];
} else if ( isAddingColumn ) {
innerBlocks = [
...innerBlocks,
...times( newColumns - previousColumns, () => {
return createBlock( 'core/column' );
return createBlock( 'core/column', {
allowedBlocks: allowedChildBlocks,
} );
} ),
];
} else {
Expand Down