Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Image block - Lightbox Button position #67042

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions packages/block-library/src/image/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,11 @@ const { state, actions, callbacks } = store(
const buttonOffsetTop = figureHeight - offsetHeight;
const buttonOffsetRight = figureWidth - offsetWidth;

let imageButtonTop = buttonOffsetTop + 16;
let imageButtonRight = buttonOffsetRight + 16;
// The button should be at most 16px from the top and right and inside the image.
// For extremely small images take the minimum of 16px or 20% of the image size.
let imageButtonTop = Math.min( offsetHeight * 0.2, 16 );
let imageButtonRight =
buttonOffsetRight + Math.min( offsetWidth * 0.2, 16 );

// In the case of an image with object-fit: contain, the size of the
// <img> element can be larger than the image itself, so it needs to
Expand Down
8 changes: 5 additions & 3 deletions test/e2e/specs/editor/blocks/image.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -985,9 +985,11 @@ test.describe( 'Image - lightbox', () => {
const postId = await editor.publishPost();
await page.goto( `/?p=${ postId }` );

const lightboxImage = page.locator( '.wp-lightbox-container img' );
await expect( lightboxImage ).toBeVisible();
await lightboxImage.click();
const imageLightboxTrigger = page.locator(
'.wp-lightbox-container .lightbox-trigger'
);
await expect( imageLightboxTrigger ).toBeVisible();
await imageLightboxTrigger.click();

const figure = page
.locator( '.wp-lightbox-overlay .wp-block-image' )
Expand Down
Loading