gearheads
/
mastodon
Archived
2
0
Fork 0

Add alt attribute to ImageLoader (#3765)

gh/stable
Yamagishi Kazutoshi 2017-06-15 21:10:41 +09:00 committed by Eugen Rochko
parent 51b2f789bd
commit df4f4e94b3
1 changed files with 10 additions and 3 deletions

View File

@ -4,12 +4,17 @@ import PropTypes from 'prop-types';
class ImageLoader extends React.PureComponent { class ImageLoader extends React.PureComponent {
static propTypes = { static propTypes = {
alt: PropTypes.string,
src: PropTypes.string.isRequired, src: PropTypes.string.isRequired,
previewSrc: PropTypes.string.isRequired, previewSrc: PropTypes.string.isRequired,
width: PropTypes.number.isRequired, width: PropTypes.number.isRequired,
height: PropTypes.number.isRequired, height: PropTypes.number.isRequired,
} }
static defaultProps = {
alt: '',
};
state = { state = {
loading: true, loading: true,
error: false, error: false,
@ -35,12 +40,13 @@ class ImageLoader extends React.PureComponent {
} }
render() { render() {
const { src, previewSrc, width, height } = this.props; const { alt, src, previewSrc, width, height } = this.props;
const { loading, error } = this.state; const { loading, error } = this.state;
return ( return (
<div className='image-loader'> <div className='image-loader'>
<img // eslint-disable-line jsx-a11y/img-has-alt <img
alt={alt}
className='image-loader__img' className='image-loader__img'
src={src} src={src}
width={width} width={width}
@ -48,7 +54,8 @@ class ImageLoader extends React.PureComponent {
/> />
{loading && {loading &&
<img // eslint-disable-line jsx-a11y/img-has-alt <img
alt=''
src={previewSrc} src={previewSrc}
className='image-loader__preview-img' className='image-loader__preview-img'
/> />