Skip to content

Commit

Permalink
MediaUpload: Ensure current images in a gallery are selected after op…
Browse files Browse the repository at this point in the history
…ening media library (#35070)
  • Loading branch information
andrewserong authored Sep 26, 2021
1 parent efaa86b commit 293f256
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions packages/media-utils/src/components/media-upload/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,15 +387,26 @@ class MediaUpload extends Component {
return;
}

if ( ! this.props.gallery ) {
const selection = this.frame.state().get( 'selection' );
const isGallery = this.props.gallery;
const selection = this.frame.state().get( 'selection' );

if ( ! isGallery ) {
castArray( this.props.value ).forEach( ( id ) => {
selection.add( wp.media.attachment( id ) );
} );
}

// load the images so they are available in the media modal.
getAttachmentsCollection( castArray( this.props.value ) ).more();
// Load the images so they are available in the media modal.
const attachments = getAttachmentsCollection(
castArray( this.props.value )
);

// Once attachments are loaded, set the current selection.
attachments.more().done( function () {
if ( isGallery && attachments?.models?.length ) {
selection.add( attachments.models );
}
} );
}

onClose() {
Expand Down

0 comments on commit 293f256

Please sign in to comment.