Skip to content

Commit

Permalink
add alt text in featured image (editor)
Browse files Browse the repository at this point in the history
  • Loading branch information
ntsekouras committed Aug 17, 2020
1 parent 1807b48 commit 48e7d4c
Showing 1 changed file with 28 additions and 19 deletions.
47 changes: 28 additions & 19 deletions packages/block-library/src/latest-posts/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,12 @@ class LatestPostsEdit extends Component {
excerptElement.innerText ||
'';

const imageSourceUrl = post.featuredImageSourceUrl;
const {
featuredImageInfo: {
url: imageSourceUrl,
alt: featuredImageAlt,
} = {},
} = post;
const imageClasses = classnames( {
'wp-block-latest-posts__featured-image': true,
[ `align${ featuredImageAlign }` ]: !! featuredImageAlign,
Expand All @@ -410,7 +415,7 @@ class LatestPostsEdit extends Component {
const featuredImage = renderFeaturedImage && (
<img
src={ imageSourceUrl }
alt=""
alt={ featuredImageAlt }
style={ {
maxWidth: featuredImageSizeWidth,
maxHeight: featuredImageSizeHeight,
Expand Down Expand Up @@ -564,24 +569,28 @@ export default withSelect( ( select, props ) => {
latestPosts: ! Array.isArray( posts )
? posts
: posts.map( ( post ) => {
if ( post.featured_media ) {
const image = getMedia( post.featured_media );
let url = get(
image,
[
'media_details',
'sizes',
featuredImageSizeSlug,
'source_url',
],
null
);
if ( ! url ) {
url = get( image, 'source_url', null );
}
return { ...post, featuredImageSourceUrl: url };
if ( ! post.featured_media ) return post;

const image = getMedia( post.featured_media );
let url = get(
image,
[
'media_details',
'sizes',
featuredImageSizeSlug,
'source_url',
],
null
);
if ( ! url ) {
url = get( image, 'source_url', null );
}
return post;
const featuredImageInfo = {
url,
// eslint-disable-next-line camelcase
alt: image?.alt_text,
};
return { ...post, featuredImageInfo };
} ),
};
} )( LatestPostsEdit );

0 comments on commit 48e7d4c

Please sign in to comment.