Skip to content

Commit

Permalink
Fix: Alt text written on images while the image was temporary is dele…
Browse files Browse the repository at this point in the history
…ted when the upload finishes.
  • Loading branch information
jorgefilipecosta committed Jul 26, 2019
1 parent 50880f6 commit b5e62ef
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions packages/block-library/src/image/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
isEmpty,
map,
last,
omit,
pick,
} from 'lodash';

Expand Down Expand Up @@ -295,7 +296,6 @@ export class ImageEdit extends Component {
attributes,
mediaUpload,
noticeOperations,
setAttributes,
} = this.props;
const { id, url = '' } = attributes;

Expand All @@ -306,7 +306,7 @@ export class ImageEdit extends Component {
mediaUpload( {
filesList: [ file ],
onFileChange: ( [ image ] ) => {
setAttributes( pickRelevantMediaFiles( image ) );
this.onSelectImage( image );
},
allowedTypes: ALLOWED_MEDIA_TYPES,
onError: ( message ) => {
Expand Down Expand Up @@ -357,7 +357,21 @@ export class ImageEdit extends Component {
isEditing: false,
} );

const { id, url } = this.props.attributes;
const { id, url, alt, caption } = this.props.attributes;

let mediaAttributes = pickRelevantMediaFiles( media );

// If the current image is temporary but an alt or caption text was meanwhile written by the user,
// make sure the text is not overwritten.
if ( isTemporaryImage( id, url ) ) {
if ( alt ) {
mediaAttributes = omit( mediaAttributes, [ 'alt' ] );
}
if ( caption ) {
mediaAttributes = omit( mediaAttributes, [ 'caption' ] );
}
}

let additionalAttributes;
// Reset the dimension attributes if changing to a different image.
if ( ! media.id || media.id !== id ) {
Expand All @@ -372,7 +386,7 @@ export class ImageEdit extends Component {
}

this.props.setAttributes( {
...pickRelevantMediaFiles( media ),
...mediaAttributes,
...additionalAttributes,
} );
}
Expand Down

0 comments on commit b5e62ef

Please sign in to comment.