Skip to content

Commit

Permalink
Image block: Set image display to grid when no alignment set to prope…
Browse files Browse the repository at this point in the history
…rly align caption on resize (#35787)

Co-authored-by: Glen Davies <[email protected]>
  • Loading branch information
glendaviesnz and Glen Davies authored Dec 9, 2021
1 parent e0c318d commit d718629
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
18 changes: 18 additions & 0 deletions packages/block-library/src/image/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,24 @@ figure.wp-block-image:not(.wp-block) {
}
}

*:not([data-align]) {
> .wp-block-image {
display: grid;
grid-template-columns: [image] minmax(0, max-content) [placeholder] auto;
.components-placeholder {
grid-column: placeholder;
}
> div:not(.components-placeholder) {
grid-column: image;
}
> figcaption {
grid-column: image;
display: table-caption;
caption-side: bottom;
}
}
}

.wp-block[data-align="left"] > .wp-block-image {
margin-right: 1em;
margin-left: 0;
Expand Down
3 changes: 3 additions & 0 deletions packages/e2e-tests/specs/editor/blocks/cover.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ describe( 'Cover', () => {
await insertBlock( 'Image' );
// Upload image and transform to the Cover block
await upload( '.wp-block-image' );
// Click the block wrapper before trying to convert to make sure figcaption toolbar is not obscuring
// the block toolbar.
await page.click( '.wp-block-image' );
await transformBlockTo( 'Cover' );

// Get the block's background dim color and its opacity
Expand Down
5 changes: 3 additions & 2 deletions packages/e2e-tests/specs/editor/blocks/image.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ describe( 'Image', () => {
`<!-- wp:image {"id":\\d+,"sizeSlug":"full","linkDestination":"none"} -->\\s*<figure class="wp-block-image size-full"><img src="[^"]+\\/${ filename2 }\\.png" alt="" class="wp-image-\\d+"/></figure>\\s*<!-- \\/wp:image -->`
);
expect( await getEditedPostContent() ).toMatch( regex3 );

await page.click( '.wp-block-image' );
// For some reason just clicking the block wrapper causes figcaption to get focus
// in puppeteer but not in live browser, so clicking on the image wrapper div here instead.
await page.click( '.wp-block-image > div' );
await page.keyboard.press( 'Backspace' );

expect( await getEditedPostContent() ).toBe( '' );
Expand Down

0 comments on commit d718629

Please sign in to comment.