Skip to content

Commit

Permalink
Add image alt
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Jun 11, 2020
1 parent 9bc36b6 commit c420dc5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
31 changes: 16 additions & 15 deletions packages/block-library/src/image/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,12 +436,28 @@ export function ImageEdit( {
);
}

const filename = getFilename( url );
let defaultedAlt;

if ( alt ) {
defaultedAlt = alt;
} else if ( filename ) {
defaultedAlt = sprintf(
/* translators: %s: file name */
__( 'This image has an empty alt attribute; its file name is %s' ),
filename
);
} else {
defaultedAlt = __( 'This image has an empty alt attribute' );
}

if ( isEditingImage ) {
return (
<Block.figure ref={ ref } className={ classes }>
<ImageEditor
id={ id }
url={ url }
alt={ defaultedAlt }
setAttributes={ setAttributes }
setIsEditingImage={ setIsEditingImage }
/>
Expand Down Expand Up @@ -515,21 +531,6 @@ export function ImageEdit( {
</>
);

const filename = getFilename( url );
let defaultedAlt;

if ( alt ) {
defaultedAlt = alt;
} else if ( filename ) {
defaultedAlt = sprintf(
/* translators: %s: file name */
__( 'This image has an empty alt attribute; its file name is %s' ),
filename
);
} else {
defaultedAlt = __( 'This image has an empty alt attribute' );
}

let img = (
// Disable reason: Image itself is not meant to be interactive, but
// should direct focus to block.
Expand Down
3 changes: 2 additions & 1 deletion packages/block-library/src/image/image-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ function AspectMenu( { isDisabled, onClick, toggleProps } ) {
export default function ImageEditor( {
id,
url,
alt,
setAttributes,
setIsEditingImage,
} ) {
Expand Down Expand Up @@ -263,7 +264,7 @@ export default function ImageEditor( {
/>
</div>
) : (
<img alt="" src={ url } />
<img alt={ alt } src={ url } />
) }
</div>
<BlockControls>
Expand Down

0 comments on commit c420dc5

Please sign in to comment.