Skip to content
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
9 changes: 6 additions & 3 deletions packages/block-library/src/image/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -602,8 +602,8 @@ export default function Image( {
} else {
const numericRatio = aspectRatio && evalAspectRatio( aspectRatio );
const customRatio = numericWidth / numericHeight;
const ratio =
numericRatio || customRatio || naturalWidth / naturalHeight || 1;
const naturalRatio = naturalWidth / naturalHeight;
const ratio = numericRatio || customRatio || naturalRatio || 1;
const currentWidth =
! numericWidth && numericHeight
? numericHeight * ratio
Expand Down Expand Up @@ -694,7 +694,10 @@ export default function Image( {
setAttributes( {
width: `${ elt.offsetWidth }px`,
height: 'auto',
aspectRatio: `${ ratio }`,
aspectRatio:
ratio === naturalRatio
? undefined

@ajlende ajlende Aug 4, 2023 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this explicitly need to be 'auto'? In most cases undefined/unset is treated as auto.

@ajlende ajlende Aug 4, 2023 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main difference is how it interacts with external CSS. Setting 'auto' will output the inline CSS, overriding the external value; whereas, undefined will output nothing, so it doesn't get overridden.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you changed it already :)

@ajlende ajlende Aug 7, 2023 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@scruffian I guess my question is, do you think this should be overridable by external CSS?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's best to leave it unset

: String( ratio ),
} );
} }
resizeRatio={ align === 'center' ? 2 : 1 }
Expand Down