Skip to content

Commit

Permalink
fix(common): update size error to mention 'fill' mode (angular#47797)
Browse files Browse the repository at this point in the history
The current error that is thrown when the "width" or
"height" attributes is missing doesn't mention that
"fill" mode is another option. This commit updates
the error with that option.

PR Close angular#47797
  • Loading branch information
kara authored and trekladyone committed Feb 1, 2023
1 parent e39302c commit 896537a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Expand Up @@ -814,7 +814,8 @@ function assertNonEmptyWidthAndHeight(dir: NgOptimizedImage) {
`${imgDirectiveDetails(dir.ngSrc)} these required attributes ` +
`are missing: ${missingAttributes.map(attr => `"${attr}"`).join(', ')}. ` +
`Including "width" and "height" attributes will prevent image-related layout shifts. ` +
`To fix this, include "width" and "height" attributes on the image tag.`);
`To fix this, include "width" and "height" attributes on the image tag or turn on ` +
`"fill" mode with the \`fill\` attribute.`);
}
}

Expand Down
9 changes: 6 additions & 3 deletions packages/common/test/directives/ng_optimized_image_spec.ts
Expand Up @@ -344,7 +344,8 @@ describe('Image directive', () => {
'element with the `ngSrc="img.png"`) has detected that these ' +
'required attributes are missing: "width", "height". Including "width" and ' +
'"height" attributes will prevent image-related layout shifts. ' +
'To fix this, include "width" and "height" attributes on the image tag.');
'To fix this, include "width" and "height" attributes on the image tag or turn on ' +
'"fill" mode with the `fill` attribute.');
});

it('should throw if `width` is not set', () => {
Expand All @@ -360,7 +361,8 @@ describe('Image directive', () => {
'element with the `ngSrc="img.png"`) has detected that these ' +
'required attributes are missing: "width". Including "width" and ' +
'"height" attributes will prevent image-related layout shifts. ' +
'To fix this, include "width" and "height" attributes on the image tag.');
'To fix this, include "width" and "height" attributes on the image tag or turn on ' +
'"fill" mode with the `fill` attribute.');
});

it('should throw if `width` is 0', () => {
Expand Down Expand Up @@ -406,7 +408,8 @@ describe('Image directive', () => {
'element with the `ngSrc="img.png"`) has detected that these required ' +
'attributes are missing: "height". Including "width" and "height" ' +
'attributes will prevent image-related layout shifts. ' +
'To fix this, include "width" and "height" attributes on the image tag.');
'To fix this, include "width" and "height" attributes on the image tag or turn on ' +
'"fill" mode with the `fill` attribute.');
});

it('should throw if `height` is 0', () => {
Expand Down

0 comments on commit 896537a

Please sign in to comment.