diff --git a/packages/block-library/src/cover/edit.js b/packages/block-library/src/cover/edit.js index f7c75b57376757..4bbf14c17dfd48 100644 --- a/packages/block-library/src/cover/edit.js +++ b/packages/block-library/src/cover/edit.js @@ -41,7 +41,7 @@ import { store as blockEditorStore, } from '@wordpress/block-editor'; import { __ } from '@wordpress/i18n'; -import { withDispatch } from '@wordpress/data'; +import { withDispatch, useSelect } from '@wordpress/data'; import { cover as icon } from '@wordpress/icons'; import { isBlobURL } from '@wordpress/blob'; @@ -253,7 +253,7 @@ function mediaPosition( { x, y } ) { const isTemporaryMedia = ( id, url ) => ! id && isBlobURL( url ); function CoverPlaceholder( { - hasBackground = false, + disableMediaButtons = false, children, noticeUI, noticeOperations, @@ -273,7 +273,7 @@ function CoverPlaceholder( { accept="image/*,video/*" allowedTypes={ ALLOWED_MEDIA_TYPES } notices={ noticeUI } - disableMediaButtons={ hasBackground } + disableMediaButtons={ disableMediaButtons } onError={ ( message ) => { removeAllNotices(); createErrorNotice( message ); @@ -286,6 +286,7 @@ function CoverPlaceholder( { function CoverEdit( { attributes, + clientId, isSelected, noticeUI, noticeOperations, @@ -409,6 +410,13 @@ function CoverEdit( { styleOfRef[ property ] = mediaPosition( value ); }; + const hasInnerBlocks = useSelect( + ( select ) => + select( blockEditorStore ).getBlock( clientId ).innerBlocks.length > + 0, + [ clientId ] + ); + const controls = ( <> @@ -420,12 +428,12 @@ function CoverEdit( { contentPosition: nextPosition, } ) } - isDisabled={ ! hasBackground } + isDisabled={ ! hasInnerBlocks } /> @@ -551,7 +559,7 @@ function CoverEdit( { } ); - if ( ! hasBackground ) { + if ( ! hasInnerBlocks && ! hasBackground ) { return ( <> { controls } @@ -658,7 +666,7 @@ function CoverEdit( { ) } { isUploadingMedia && }