Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
useAppender(): Check block selection before other checks
  • Loading branch information
noisysocks committed Jun 20, 2023
commit 395c064b25a07c9915e71f6df515b6cd16368496
53 changes: 27 additions & 26 deletions packages/block-editor/src/components/block-list-appender/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function DefaultAppender( { rootClientId } ) {
}

function useAppender( rootClientId, CustomAppender ) {
const { hideInserter, isParentSelected } = useSelect(
return useSelect(
( select ) => {
const {
getTemplateLock,
Expand All @@ -50,35 +50,36 @@ function useAppender( rootClientId, CustomAppender ) {
getBlockEditingMode,
} = unlock( select( blockEditorStore ) );

const selectedBlockClientId = getSelectedBlockClientId();
if ( CustomAppender === false ) {
return null;
}

return {
hideInserter:
!! getTemplateLock( rootClientId ) ||
getBlockEditingMode( rootClientId ) === 'disabled' ||
__unstableGetEditorMode() === 'zoom-out',
isParentSelected:
if ( ! CustomAppender ) {
const selectedBlockClientId = getSelectedBlockClientId();
const isParentSelected =
rootClientId === selectedBlockClientId ||
( ! rootClientId && ! selectedBlockClientId ),
};
( ! rootClientId && ! selectedBlockClientId );
if ( ! isParentSelected ) {
return null;
}
}

if (
getTemplateLock( rootClientId ) ||
getBlockEditingMode( rootClientId ) === 'disabled' ||
__unstableGetEditorMode() === 'zoom-out'
) {
return null;
}

return CustomAppender ? (
<CustomAppender />
) : (
<DefaultAppender rootClientId={ rootClientId } />
);
},
[ rootClientId ]
[ rootClientId, CustomAppender ]
);

if ( hideInserter || CustomAppender === false ) {
return null;
}

if ( CustomAppender ) {
// Prefer custom render prop if provided.
return <CustomAppender />;
}

if ( ! isParentSelected ) {
return null;
}

return <DefaultAppender rootClientId={ rootClientId } />;
}

function BlockListAppender( {
Expand Down