hzdg / react-imageloader

A React component for wrangling image loading

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Set className of <img>?

idolize opened this issue · comments

There is no way to set className of the rendered <img> tag. This is important to me, and used to work in earlier versions of this library...

The behavior is due to the fact that className is in the property "blacklist".

Perhaps an "imgClassName" prop could be added to address this?

Hmm yeah, maybe a prop is the right solution. Do you mind giving a bit more info on your use case for giving the img a class?

Sure, I just want to give my transparent .png image a different color background than white.

I know there are other workarounds, like adding a ".my-classimg" to my CSS class definition, or creating an additional wrapper component with my custom background, but styling the image directly is definitely the preferable solution.

Thanks for all the great work!

I wonder if the solution shouldn't be more generic. I mean, what makes "className" so special? Will there be other properties we want to support? Can we come up with something a little more flexible?

I've been thinking we could make a imgProps prop for this.

To expound: Instead of passing the 'extra' props given to ImageLoader down to the <img>, pass the value of imgProps.

This would be great! This would also work for accessibility tags like "alt".

👍

Added the imgProps...prop. On npm now as v2.1.0.