Skip to content
Closed
Show file tree
Hide file tree
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
Always size elements based on width
  • Loading branch information
ajlende committed Aug 1, 2023
commit 412eebbb7eda351369e6a3ca6b00f8cd66e42eb9
12 changes: 8 additions & 4 deletions packages/block-library/src/image/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,14 +484,18 @@ export default function Image( {
// for values that are removed since setAttributes
// doesn't do anything with keys that aren't set.
setAttributes( {
// width: attribute & style.
width:
newValue.width &&
parseInt( newValue.width, 10 ),
// height: attribute only, style is 'auto'.
height:
newValue.height &&
parseInt( newValue.height, 10 ),
scale: newValue.scale,
aspectRatio: newValue.aspectRatio,
aspectRatio:
newValue.aspectRatio ||
newValue.width / newValue.height,
} );
} }
defaultScale="cover"
Expand Down Expand Up @@ -688,9 +692,9 @@ export default function Image( {
onResizeStop={ ( event, direction, elt ) => {
onResizeStop();
setAttributes( {
width: elt.offsetWidth,
height: elt.offsetHeight,
aspectRatio: undefined,
width: elt.offsetWidth, // attribute & style.
height: elt.offsetHeight, // attribute only, style is 'auto'.
aspectRatio: elt.offsetWidth / elt.offsetHeight,
} );
} }
resizeRatio={ align === 'center' ? 2 : 1 }
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/image/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default function save( { attributes } ) {
aspectRatio,
objectFit: scale,
width,
height,
height: !! height && 'auto', // Also defined in style.scss.
} }
width={ width }
height={ height }
Expand Down