From 6b28210df80aa66cd5a88497c2bfe11749651da6 Mon Sep 17 00:00:00 2001 From: Mitchell Austin Date: Mon, 13 Jan 2025 19:23:15 -0800 Subject: [PATCH] Render only used dimension control and monopolize its conditional --- packages/block-library/src/image/image.js | 90 +++++++++++------------ 1 file changed, 42 insertions(+), 48 deletions(-) diff --git a/packages/block-library/src/image/image.js b/packages/block-library/src/image/image.js index bd38522d164357..4eaab5b7686354 100644 --- a/packages/block-library/src/image/image.js +++ b/packages/block-library/src/image/image.js @@ -530,49 +530,49 @@ export default function Image( { const dropdownMenuProps = useToolsPanelDropdownMenuProps(); - const dimensionsControl = ( - { - // Rebuilding the object forces setting `undefined` - // for values that are removed since setAttributes - // doesn't do anything with keys that aren't set. - setAttributes( { - // CSS includes `height: auto`, but we need - // `width: auto` to fix the aspect ratio when - // only height is set due to the width and - // height attributes set via the server. - width: ! newWidth && newHeight ? 'auto' : newWidth, + const dimensionsControl = + isResizable && + ( SIZED_LAYOUTS.includes( parentLayoutType ) ? ( + { + setAttributes( { + aspectRatio: newAspectRatio, + scale: 'cover', + } ); + } } + defaultAspectRatio="auto" + tools={ [ 'aspectRatio' ] } + /> + ) : ( + - ); - - const aspectRatioControl = ( - { - setAttributes( { - aspectRatio: newAspectRatio, - scale: 'cover', - } ); - } } - defaultAspectRatio="auto" - tools={ [ 'aspectRatio' ] } - /> - ); + } ) => { + // Rebuilding the object forces setting `undefined` + // for values that are removed since setAttributes + // doesn't do anything with keys that aren't set. + setAttributes( { + // CSS includes `height: auto`, but we need + // `width: auto` to fix the aspect ratio when + // only height is set due to the width and + // height attributes set via the server. + width: ! newWidth && newHeight ? 'auto' : newWidth, + height: newHeight, + scale: newScale, + aspectRatio: newAspectRatio, + } ); + } } + defaultScale="cover" + defaultAspectRatio="auto" + scaleOptions={ scaleOptions } + unitsOptions={ dimensionsUnitsOptions } + /> + ) ); const resetAll = () => { setAttributes( { @@ -592,10 +592,7 @@ export default function Image( { resetAll={ resetAll } dropdownMenuProps={ dropdownMenuProps } > - { isResizable && - ( SIZED_LAYOUTS.includes( parentLayoutType ) - ? aspectRatioControl - : dimensionsControl ) } + { dimensionsControl } ); @@ -824,10 +821,7 @@ export default function Image( { /> ) } - { isResizable && - ( SIZED_LAYOUTS.includes( parentLayoutType ) - ? aspectRatioControl - : dimensionsControl ) } + { dimensionsControl } { !! imageSizeOptions.length && (