Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cover block: Clear aspect ratio value when toggling full height #59296

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading