Skip to content

Commit

Permalink
Use clientId instead of index
Browse files Browse the repository at this point in the history
  • Loading branch information
t-hamano committed Aug 18, 2023
1 parent a0387b7 commit 4863836
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ function ListViewBlockSelectButton(
{ images.map( ( image, index ) => (
<span
className="block-editor-list-view-block-select-button__image"
key={ index }
key={ image.clientId }
style={ {
backgroundImage: `url(${ image.url })`,
zIndex: images.length - index, // Ensure the first image is on top, and subsequent images are behind.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@ import { store as blockEditorStore } from '../../store';
// Maximum number of images to display in a list view row.
const MAX_IMAGES = 3;

function getImageUrl( block ) {
function getImage( block ) {
if ( block.name !== 'core/image' ) {
return;
}

if ( block.attributes?.url ) {
return { url: block.attributes.url, alt: block.attributes.alt };
return {
url: block.attributes.url,
alt: block.attributes.alt,
clientId: block.clientId,
};
}
}

Expand All @@ -30,7 +34,7 @@ function getImagesFromGallery( block ) {
const images = [];

for ( const innerBlock of block.innerBlocks ) {
const img = getImageUrl( innerBlock );
const img = getImage( innerBlock );
if ( img ) {
images.push( img );
}
Expand All @@ -43,7 +47,7 @@ function getImagesFromGallery( block ) {
}

function getImagesFromBlock( block, isExpanded ) {
const img = getImageUrl( block );
const img = getImage( block );
if ( img ) {
return [ img ];
}
Expand Down

0 comments on commit 4863836

Please sign in to comment.