From 836d222a25b4074ad6061966e3a8429dd310deea Mon Sep 17 00:00:00 2001 From: Kara Erickson Date: Mon, 17 Oct 2022 17:23:39 -0700 Subject: [PATCH] fix(common): update size error to mention 'fill' mode 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. --- .../directives/ng_optimized_image/ng_optimized_image.ts | 3 ++- .../common/test/directives/ng_optimized_image_spec.ts | 9 ++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/common/src/directives/ng_optimized_image/ng_optimized_image.ts b/packages/common/src/directives/ng_optimized_image/ng_optimized_image.ts index d645a97e9fd7e..0970832ca4526 100644 --- a/packages/common/src/directives/ng_optimized_image/ng_optimized_image.ts +++ b/packages/common/src/directives/ng_optimized_image/ng_optimized_image.ts @@ -830,7 +830,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.`); } } diff --git a/packages/common/test/directives/ng_optimized_image_spec.ts b/packages/common/test/directives/ng_optimized_image_spec.ts index 8870960cee715..a6c57947a1fe0 100644 --- a/packages/common/test/directives/ng_optimized_image_spec.ts +++ b/packages/common/test/directives/ng_optimized_image_spec.ts @@ -359,7 +359,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', () => { @@ -375,7 +376,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', () => { @@ -421,7 +423,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', () => {