diff --git a/packages/block-library/src/cover/edit/block-controls.js b/packages/block-library/src/cover/edit/block-controls.js index 59aaaaffe77d75..c4137ad2a8409a 100644 --- a/packages/block-library/src/cover/edit/block-controls.js +++ b/packages/block-library/src/cover/edit/block-controls.js @@ -8,6 +8,7 @@ import { MediaReplaceFlow, __experimentalBlockAlignmentMatrixControl as BlockAlignmentMatrixControl, __experimentalBlockFullHeightAligmentControl as FullHeightAlignmentControl, + privateApis as blockEditorPrivateApis, } from '@wordpress/block-editor'; import { __ } from '@wordpress/i18n'; @@ -15,6 +16,9 @@ import { __ } from '@wordpress/i18n'; * Internal dependencies */ import { ALLOWED_MEDIA_TYPES } from '../shared'; +import { unlock } from '../../lock-unlock'; + +const { cleanEmptyObject } = unlock( blockEditorPrivateApis ); export default function CoverBlockControls( { attributes, @@ -30,7 +34,10 @@ export default function CoverBlockControls( { const [ prevMinHeightValue, setPrevMinHeightValue ] = useState( minHeight ); const [ prevMinHeightUnit, setPrevMinHeightUnit ] = useState( minHeightUnit ); - const isMinFullHeight = minHeightUnit === 'vh' && minHeight === 100; + const isMinFullHeight = + minHeightUnit === 'vh' && + minHeight === 100 && + ! attributes?.style?.dimensions?.aspectRatio; const toggleMinFullHeight = () => { if ( isMinFullHeight ) { // If there aren't previous values, take the default ones. @@ -51,10 +58,17 @@ export default function CoverBlockControls( { setPrevMinHeightValue( minHeight ); setPrevMinHeightUnit( minHeightUnit ); - // Set full height. + // Set full height, and clear any aspect ratio value. return setAttributes( { minHeight: 100, minHeightUnit: 'vh', + style: cleanEmptyObject( { + ...attributes?.style, + dimensions: { + ...attributes?.style?.dimensions, + aspectRatio: undefined, // Reset aspect ratio when minHeight is set. + }, + } ), } ); };