Skip to content

Commit

Permalink
Cover block: Clear aspect ratio value when toggling full height (#59296)
Browse files Browse the repository at this point in the history
* Cover block: Clear aspect ratio value when toggling full height

* Tweak isMinFullHeight logic

Co-authored-by: andrewserong <[email protected]>
Co-authored-by: fabiankaegy <[email protected]>
Co-authored-by: jasmussen <[email protected]>
  • Loading branch information
4 people authored and getdave committed Feb 27, 2024
1 parent 3e81f13 commit bab29cc
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions packages/block-library/src/cover/edit/block-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ import {
MediaReplaceFlow,
__experimentalBlockAlignmentMatrixControl as BlockAlignmentMatrixControl,
__experimentalBlockFullHeightAligmentControl as FullHeightAlignmentControl,
privateApis as blockEditorPrivateApis,
} from '@wordpress/block-editor';
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,
Expand All @@ -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.
Expand All @@ -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.
},
} ),
} );
};

Expand Down

0 comments on commit bab29cc

Please sign in to comment.