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

Group Block: Allow blocks to be dragged onto it in its placeholder state #49361

Merged
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
34 changes: 25 additions & 9 deletions packages/block-library/src/group/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from '@wordpress/block-editor';
import { SelectControl } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { View } from '@wordpress/primitives';

/**
* Internal dependencies
Expand Down Expand Up @@ -108,16 +109,28 @@ function GroupEdit( {
usedLayoutType: usedLayout?.type,
hasInnerBlocks,
} );

// Default to the regular appender being rendered.
let renderAppender;
if ( showPlaceholder ) {
// In the placeholder state, ensure the appender is not rendered.
// This is needed because `...innerBlocksProps` is used in the placeholder
// state so that blocks can dragged onto the placeholder area
// from both the list view and in the editor canvas.
renderAppender = false;
} else if ( ! hasInnerBlocks ) {
// When there is no placeholder, but the block is also empty,
// use the larger button appender.
renderAppender = InnerBlocks.ButtonBlockAppender;
}

const innerBlocksProps = useInnerBlocksProps(
layoutSupportEnabled
? blockProps
: { className: 'wp-block-group__inner-container' },
{
templateLock,
renderAppender: hasInnerBlocks
? undefined
: InnerBlocks.ButtonBlockAppender,
__unstableDisableLayoutClassNames: ! layoutSupportEnabled,
renderAppender,
}
);

Expand All @@ -138,11 +151,14 @@ function GroupEdit( {
}
/>
{ showPlaceholder && (
<GroupPlaceHolder
clientId={ clientId }
name={ name }
onSelect={ selectVariation }
/>
<View { ...innerBlocksProps }>
{ innerBlocksProps.children }
<GroupPlaceHolder
clientId={ clientId }
name={ name }
onSelect={ selectVariation }
/>
</View>
) }
{ layoutSupportEnabled && ! showPlaceholder && (
<TagName { ...innerBlocksProps } />
Expand Down