Skip to content

Commit

Permalink
Only render button appender when the group has no inner blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
talldan committed Apr 18, 2019
1 parent c5f27fa commit 443822c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 18 deletions.
16 changes: 3 additions & 13 deletions packages/block-library/src/group/edit.js
Expand Up @@ -17,13 +17,13 @@ import {
withColors,
} from '@wordpress/block-editor';

const renderAppender = () => <InnerBlocks.ButtonBlockAppender />;

function GroupEdit( {
className,
setBackgroundColor,
backgroundColor,
isSelected,
hasInnerBlocks,
isInnerBlockSelected,
} ) {
const styles = {
backgroundColor: backgroundColor.color,
Expand All @@ -33,12 +33,6 @@ function GroupEdit( {
'has-background': !! backgroundColor.color,
} );

const isAppenderVisible = (
isSelected ||
isInnerBlockSelected ||
! hasInnerBlocks
);

return (
<Fragment>
<InspectorControls>
Expand All @@ -55,9 +49,7 @@ function GroupEdit( {
</InspectorControls>
<div className={ classes } style={ styles }>
<InnerBlocks
renderAppender={ () => (
isAppenderVisible && <InnerBlocks.ButtonBlockAppender />
) }
renderAppender={ ! hasInnerBlocks && renderAppender }
/>
</div>
</Fragment>
Expand All @@ -69,14 +61,12 @@ export default compose( [
withSelect( ( select, { clientId } ) => {
const {
getBlock,
hasSelectedInnerBlock,
} = select( 'core/block-editor' );

const block = getBlock( clientId );

return {
hasInnerBlocks: !! ( block && block.innerBlocks.length ),
isInnerBlockSelected: hasSelectedInnerBlock( clientId, true ),
};
} ),
] )( GroupEdit );
5 changes: 0 additions & 5 deletions packages/e2e-tests/specs/blocks/group.test.js
Expand Up @@ -31,13 +31,8 @@ describe( 'Group', () => {
it( 'can have other blocks appended to it using the button appender', async () => {
await searchForBlock( 'Group' );
await page.click( '.editor-block-list-item-group' );

await page.waitForSelector( '.block-editor-button-block-appender' );
await page.click( '.block-editor-button-block-appender' );

await page.waitForSelector( '.editor-block-list-item-paragraph' );
await page.click( '.editor-block-list-item-paragraph' );

await page.keyboard.type( 'Group Block with a Paragraph' );

expect( await getEditedPostContent() ).toMatchSnapshot();
Expand Down

0 comments on commit 443822c

Please sign in to comment.