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

[draft] Add 'fill mode' to NgOptimizedImage #47727

Closed
wants to merge 2 commits into from

Conversation

atcastle
Copy link
Contributor

This PR creates a new boolean attribute on the ngOptimizedImage directive called fill, which allows the directive to be used without height and width, and which automatically styles the image to fill it's containing element.

This PR still requires some additional test cases before merging. Posting now for feedback from @AndrewKushnir and @pkozlowski-opensource. CC: @kara

Add a feature to automatically generate the srcset attribute for images using the NgOptimizedImage directive. Uses the 'sizes' attribute to determine the appropriate srcset to generate.
Add a boolean attribute called 'fill' to the ngOptimizedImage directive, which removes the need for height and width, and adds styling to make the image fill its container.
@angular-robot angular-robot bot added the feature Issue that requests a new feature label Oct 11, 2022
this.setHostAttribute('width', this.width!.toString());
this.setHostAttribute('height', this.height!.toString());
if (this.fill) {
this.setHostAttribute('style', this.getFillStyle())
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it'd be great to avoid custom parsing of styles and writing them directly to the DOM via renderer.

The "style" attribute values are handled by the framework and it takes into account various use-cases which might be broken because of writing to the DOM directly.

Instead, we can try to lean on the framework functionality and set extra styles via host binding, similar to this example:

https://github.com/angular/components/blob/f9583184d6ca487970ee70a1c05cec6e36f3e18c/src/material/legacy-progress-spinner/progress-spinner.ts#L100-L101

This would delegate the styling processing, overrides and handing of the "style" attribute bindings to the framework. WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

(I think this is actually a necessity, otherwise this call would clobber user-applied style bindings).

top: '0',
right: '0',
bottom: '0'
} let providedStyles: {[key: string]: string|number} = {} if (this.style) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like some semicolons are missing, thus the formatting is broken.

@AndrewKushnir AndrewKushnir added the target: major This PR is targeted for the next major release label Oct 11, 2022
@ngbot ngbot bot removed this from the v15 feature freeze blockers milestone Oct 11, 2022
@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
Copy link
Contributor Author

With @AndrewKushnir and @kara's guidance I re-implemented this feature differently. I opened a new PR since this one was also having some merge issue: #47738
Closing this one.

@atcastle atcastle closed this Oct 11, 2022
@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 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: common Issues related to APIs in the @angular/common package feature Issue that requests a new feature target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants