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

Block Editor: Fix Multiple Trailing Inserters for Nested Inner Blocks #24836

Merged
merged 4 commits into from
Sep 3, 2020
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
25 changes: 22 additions & 3 deletions packages/block-editor/src/components/block-list-appender/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ function BlockListAppender( {
isLocked,
renderAppender: CustomAppender,
className,
selectedBlockClientId,
tagName: TagName = 'div',
} ) {
if ( isLocked || CustomAppender === false ) {
Expand All @@ -40,6 +41,20 @@ function BlockListAppender( {
} else if ( canInsertDefaultBlock ) {
// Render the default block appender when renderAppender has not been
// provided and the context supports use of the default appender.
const isDocumentAppender = ! rootClientId;
const isParentSelected = selectedBlockClientId === rootClientId;
const isAnotherDefaultAppenderAlreadyDisplayed =
selectedBlockClientId &&
! blockClientIds.includes( selectedBlockClientId );

if (
! isDocumentAppender &&
! isParentSelected &&
isAnotherDefaultAppenderAlreadyDisplayed
) {
return null;
}

appender = (
<DefaultBlockAppender
rootClientId={ rootClientId }
Expand Down Expand Up @@ -79,9 +94,12 @@ function BlockListAppender( {
}

export default withSelect( ( select, { rootClientId } ) => {
const { getBlockOrder, canInsertBlockType, getTemplateLock } = select(
'core/block-editor'
);
const {
getBlockOrder,
canInsertBlockType,
getTemplateLock,
getSelectedBlockClientId,
} = select( 'core/block-editor' );

return {
isLocked: !! getTemplateLock( rootClientId ),
Expand All @@ -90,5 +108,6 @@ export default withSelect( ( select, { rootClientId } ) => {
getDefaultBlockName(),
rootClientId
),
selectedBlockClientId: getSelectedBlockClientId(),
};
} )( BlockListAppender );