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

Image block: Fix aspect-ratio with max-width #53250

Closed
wants to merge 1 commit into from
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
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