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

Support srcset in CardMedia #11675

Closed
2 tasks done
kaycebasques opened this issue Jun 1, 2018 · 7 comments
Closed
2 tasks done

Support srcset in CardMedia #11675

kaycebasques opened this issue Jun 1, 2018 · 7 comments
Labels
component: card This is the name of the generic UI component, not the React module! new feature New feature or request
Milestone

Comments

@kaycebasques
Copy link

CardMedia component doesn't seem to support responsive images.

  • This is a v1.x issue (v0.x is no longer maintained).
  • I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior

Should be able to pass in a srcset attribute for image components in general.

Current Behavior

Not supported?

https://material-ui.com/api/card-media/

@oliviertassinari
Copy link
Member

oliviertassinari commented Jun 1, 2018

It's not. We would need to use a <img> element over a background image.
By the way, it would be better for SEO and accessibility to use an image element over a CSS background image.

@oliviertassinari oliviertassinari added new feature New feature or request component: card This is the name of the generic UI component, not the React module! labels Jun 1, 2018
@oliviertassinari
Copy link
Member

It seems that supporting this feature would require us to rely on the object-fit: cover; CSS property. Something IE 11 doesn't support. We might have to wait 1 year or 2 before moving this issue forward. In the meantime, I fear the best alternative is to do it programatically in JavaScript.

@adeelibr
Copy link
Contributor

adeelibr commented Jun 4, 2018

We can do something like this as an alternative to object-fit: cover; https://codepen.io/studiotwist/pen/XdgqmZ?editors=0100

@oliviertassinari
Copy link
Member

@adeelibr Thanks for sharing. I guess we can start experimenting with this workaround.

@adeelibr
Copy link
Contributor

adeelibr commented Jun 6, 2018

@oliviertassinari Can i experiment with this?

@adeelibr
Copy link
Contributor

#12481 I have for now added a separate code for only Component type "img", If this feels okay, can i remove the rest and only keep the image part Line 46 to Line 51 in CardMedia.js @oliviertassinari

@oliviertassinari
Copy link
Member

@kaycebasques Actually, it's supported, you can use the component property to render an image over a div with a background image.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: card This is the name of the generic UI component, not the React module! new feature New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants