Skip to content

Commit

Permalink
Fix behavior of renderAppender when standalone
Browse files Browse the repository at this point in the history
  • Loading branch information
jrtashjian committed Aug 12, 2024
1 parent 47acec8 commit f7f68d4
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions packages/block-library/form/edit/standalone-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import {
useBlockProps,
useInnerBlocksProps,
InnerBlocks,
Warning,
store as blockEditorStore,
} from '@wordpress/block-editor';
Expand Down Expand Up @@ -155,30 +156,37 @@ export default function StandaloneForm( blockObject ) {
clientId,
} = blockObject;

const blockProps = useBlockProps( {
className: 'block-library-block__reusable-block-container',
} );

const innerBlockProps = useInnerBlocksProps( blockProps, {
allowedBlocks: ALLOWED_BLOCKS,
template: TEMPLATE,
} );

const isNested = useSelect(
const { isNested, hasInnerBlocks } = useSelect(
( select ) => {
const {
getBlockParents,
getBlock,
getBlockCount,
} = select( blockEditorStore );

const parentBlocks = getBlockParents( clientId );
const rootBlock = getBlock( parentBlocks[ 0 ] );

return rootBlock?.name === name;
return {
isNested: rootBlock?.name === name,
hasInnerBlocks: getBlockCount( clientId ) > 0,
};
},
[ clientId, name ]
);

const blockProps = useBlockProps( {
className: 'block-library-block__reusable-block-container',
} );

const innerBlockProps = useInnerBlocksProps( blockProps, {
allowedBlocks: ALLOWED_BLOCKS,
template: TEMPLATE,
renderAppender: hasInnerBlocks
? undefined
: InnerBlocks.ButtonBlockAppender,
} );

if ( isNested ) {
return (
<div { ...blockProps }>
Expand Down

0 comments on commit f7f68d4

Please sign in to comment.