Skip to content

feat(common): Add fill mode to NgOptimizedImage#47738

Closed
atcastle wants to merge 1 commit intoangular:mainfrom
atcastle:fill-mode-2
Closed

feat(common): Add fill mode to NgOptimizedImage#47738
atcastle wants to merge 1 commit intoangular:mainfrom
atcastle:fill-mode-2

Conversation

@atcastle
Copy link
Contributor

This PR adds a new boolean attribute to NgOptimizedImage called fill which does the following:

  • Removes the requirement for height and width
  • Adds inline styling to cause the image to fill its containing element
  • Adds a default sizes value of 100vw which will cause the image to have a responsive srcset automatically generated

CC: @AndrewKushnir @pkozlowski-opensource @kara

@pullapprove pullapprove bot requested a review from AndrewKushnir October 11, 2022 20:44
@angular-robot angular-robot bot added the feature Label used to distinguish feature request from other issues label Oct 11, 2022
Copy link
Contributor

@kara kara left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

Choose a reason for hiding this comment

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

(can be follow up PR): can we add something here about why width and height aren't necessary? e.g. that we usually require them to prevent layout shift but here it's unnecessary

@jessicajaniuk jessicajaniuk added the area: common Issues related to APIs in the @angular/common package label Oct 11, 2022
@ngbot ngbot bot added this to the Backlog milestone Oct 11, 2022
@atcastle atcastle force-pushed the fill-mode-2 branch 2 times, most recently from cf716ca to aab6ef8 Compare October 11, 2022 22:00
Add a new boolean attribute to NgOptimizedImage called `fill` which does the following:
* Removes the requirement for height and width
* Adds inline styling to cause the image to fill its containing element
* Adds a default `sizes` value of `100vw` which will cause the image to have a responsive srcset automatically generated
@jessicajaniuk jessicajaniuk added the target: major This PR is targeted for the next major release label Oct 11, 2022
Copy link
Contributor

@AndrewKushnir AndrewKushnir left a comment

Choose a reason for hiding this comment

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

LGTM 👍

I've left some comments, but they can all be addressed in a followup PR.

private _disableOptimizedSrcset = false;

/**
* Sets the image to "fill mode," which eliminates the height/width requirement and adds
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: typo, let's fix it in a followup PR.

Suggested change
* Sets the image to "fill mode," which eliminates the height/width requirement and adds
* Sets the image to "fill mode", which eliminates the height/width requirement and adds

Comment on lines 407 to +416
// Must set width/height explicitly in case they are bound (in which case they will
// only be reflected and not found by the browser)
this.setHostAttribute('width', this.width!.toString());
this.setHostAttribute('height', this.height!.toString());
if (this.fill) {
if (!this.sizes) {
this.sizes = '100vw';
}
} else {
this.setHostAttribute('width', this.width!.toString());
this.setHostAttribute('height', this.height!.toString());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I think this section would require some extra comments (and updates to existing ones):

  • the width/height comment can be updated to better reflect the logic
  • it's be great to add a comment on why we define sizes as 100vw (related question: what happens when the sizes are defined differently by a user?)
  • we could also add a quick comment above the code that sets width/height and explain why we don't do it for "fill" mode

We could do it in a followup PR as well.

imgDirectiveDetails(
dir.ngSrc)} the attributes \`height\` and/or \`width\` are present ` +
`along with the \`fill\` attribute. Because \`fill\` mode causes an image to fill its containing ` +
`element, the size attributes have no effect and should be removed.`);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: the size might be confused with the sizes input, so we can rephrase this a bit:

Suggested change
`element, the size attributes have no effect and should be removed.`);
`element, the width/height attributes have no effect and should be removed.`);

Copy link
Contributor

@AndrewKushnir AndrewKushnir left a comment

Choose a reason for hiding this comment

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

Reviewed-for: public-api

@AndrewKushnir AndrewKushnir added action: merge The PR is ready for merge by the caretaker merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note labels Oct 12, 2022
@AndrewKushnir
Copy link
Contributor

Merge-assistance (cc @jessicajaniuk):

  • The PR was reviewed and approved, the only missing item is one more pubic-api approval. Could you please take a quick look at the changes from the pubic-api perspective (the changes are pretty small, just an extra @Input)?
  • There is some minor feedback (mostly docs-related), which we'll take care of in a followup PR.

Overall status (after public-api approval) of this PR: ready for merge.

Copy link
Contributor

@jessicajaniuk jessicajaniuk left a comment

Choose a reason for hiding this comment

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

reviewed-for: public-api

@jessicajaniuk jessicajaniuk added merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note and removed merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note labels Oct 12, 2022
@jessicajaniuk
Copy link
Contributor

This PR was merged into the repository by commit 9483343.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Nov 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: common Issues related to APIs in the @angular/common package feature Label used to distinguish feature request from other issues merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note target: major This PR is targeted for the next major release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants