Skip to content
This repository was archived by the owner on Jan 6, 2025. It is now read-only.

feat(img-srcset): add ImgSrcsetDirective for progressive images #383

Closed
wants to merge 1 commit into from

Conversation

ThomasBurleson
Copy link
Contributor

@ThomasBurleson ThomasBurleson commented Aug 18, 2017

Support responsive image by introducing srcset. directive. When used as <img> attributes where

  • where the <img> is a child of a <picture> container, this directive will injects a <source> element for every srcset..
<picture>
   <img  [src]="defaultSrc"
         [srcset.md]="mdSrcset"
         [srcset.xs]="xsSrcset" >
</picture>
  • where the <img> is NOT nested in a <picture> element, then the img.src property will be responsively updated.
<img  [src]="defaultSrc"
      [srcset.md]="mdSrcset"
      [srcset.xs]="xsSrcset" >

Thanks to @benbraou for his initial PR submission (@see #366)

Closes #81.

Support responsive image by introducing srcset.<breakpoint alias> directive. When used as <img> attributes where

*  where the <img> is a child of a <picture> container, this directive will injects a <source> element for every srcset.<breakpoint alias>.
*  where the <img> is NOT nested in a <picture> element, then the `img.src` property will be responsively updated.

> Thanks to @benbraou for his initial PR submission (@see #366)

Closes #81.
@ThomasBurleson ThomasBurleson added this to the v2.0.0-beta.10 milestone Aug 18, 2017
@ThomasBurleson
Copy link
Contributor Author

@benbraou - Due to changes in master, it was easier to create a new PR that you and I can work on together. Thanks.

@benbraou
Copy link

@ThomasBurleson No problem. This has been a great learning experience.
I am looking at the PR. Thx

fixture.detectChanges();
expect(img).toBeDefined();
expect(img).toHaveAttributes({
src: fixture.componentInstance.mdSrcSet
Copy link

@benbraou benbraou Aug 19, 2017

Choose a reason for hiding this comment

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

@ThomasBurleson With this test, we check that the src attribute is updated. However, srcset is still in the dom (with the old value corresponding to xsSrcSet). In case srcset value uses the pixel density 1x, it will have the priority, and we will not have the intended behaviour. I think that the test should be updated to do validation on both src and srcset. But most importantly, what should we do? Update in this case the srcset value and not introduce src? Or update both srcset and src?


// Only responsively update srcset values for stand-alone image elements
// Fallback to [srcset] value for responsive deactivation
this._listenForMediaQueryChanges('src', '', () => {
Copy link

@benbraou benbraou Aug 20, 2017

Choose a reason for hiding this comment

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

I think the key should be 'srcset' rather than 'src' otherwise onMediaQueryChange will never be triggered since inputKeyMap contains only srcset based keys

matchMedia.activate('xs');
fixture.detectChanges();
expect(defaultSourceEl).toHaveAttributes({
srcset: 'https://dummyimage.com/400x200/c7c224/000.png&text=default'

Choose a reason for hiding this comment

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

Shouldn't the source element have the srcset value 'https://dummyimage.com/500x200/76c720/fff.png&text=md' (and the media query corresponding to md) ?

When 'xs' is activated, the injected source element should not be updated. The browser will default to the img src value.

@ThomasBurleson
Copy link
Contributor Author

ThomasBurleson commented Aug 20, 2017

@benbraou - I am OoO next week. Meanwhile let us first document how this responsive srcset is supposed to work... in all scenarios. Here is a ImgSrcsetDirective WIKI page that we can use to document the API, its uses, fallbacks, and conditions.

@benbraou
Copy link

Sure. My proposed wiki contribution will be in https://github.com/benbraou/flex-layout-wiki
I will be working on it this weekend.

@ThomasBurleson
Copy link
Contributor Author

Closing. Will resubmit with improved logic and revised approach.

@ThomasBurleson ThomasBurleson deleted the thomas/fix-img-srcset branch January 15, 2018 23:46
@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 Sep 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add new API fxSrc for responsive features Image element
3 participants