Skip to content

Commit

Permalink
Block Editor: Fix Multiple Trailing Inserters for Nested Inner Blocks (
Browse files Browse the repository at this point in the history
…#24836)

* Hide trailing inserter if siblings in the block list are not selected
* Display trailing appender when the page is empty
* Display trailing inserter when parent block is selected
  • Loading branch information
jeyip authored Sep 3, 2020
1 parent b575047 commit 5270919
Showing 1 changed file with 22 additions and 3 deletions.
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 );

0 comments on commit 5270919

Please sign in to comment.