Skip to content

[WC-3633] fix: image lightbox inherit image sizing - #2511

Merged
gjulivan merged 3 commits into
mainfrom
combobox/fix-lightbox
Nov 17, 2026
Merged

gjulivan merged 3 commits into
mainfrom
combobox/fix-lightbox

Conversation

@gjulivan

@gjulivan gjulivan commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Pull request type

Bug fix (non-breaking change which fixes an issue)


Description

Fixes WC-3633: with On click set to Enlarge, the enlarged image could be smaller than the image on the page.

Cause. The lightbox rendered a clone of the image on the page (cloneElement(content, ...)), so it kept that image's inline width, height, min-height and max-height. .mx-image-viewer-lightbox is position: fixed with no width, so it shrinks to fit its content, and a percentage width then resolves against the image's own natural width. A 338 px image with Width 50% was shown 169 px wide, and with the max height of 250 px that is the default since 1.6.0, about 126 px. A max height capped the enlarged image at the height of the image on the page, and a pixel width kept it at the size on the page.

Fix.

  • The lightbox renders its own <img> without the sizing styles (width, height, min/max width, min/max height). Other inline styles, the alt text and the img-thumbnail class are kept, as before.
  • Image.scss shows the lightbox image at its natural size, scaled down to fit the viewport (max-width: 90vw; max-height: 85vh), keeping the aspect ratio.
  • Added a unit test that the lightbox image does not take the sizing of the image on the page. It fails on the old code.
  • Changelog entry under Unreleased.

Behavior change to note. With a fixed pixel width smaller than the image, Enlarge now shows the image larger than on the page. Before, it stayed the same size.

Verified in a Mendix 11.12.5 app with Image widgets showing a 338 × 335 px image, measured with Playwright at 1440 × 900:

Image widget settings Before After
Width 50%, max height 250 px 126×125 338×335
Width 50% 169×168 338×335
Width 100%, max height 150 px 151×150 338×335
Width 120 px 120×119 338×335
Width 100% (control) 338×335 338×335

At a 400 × 300 viewport the enlarged image is 257 × 255 (85vh), centred, aspect ratio kept.

pnpm test passes (45 tests). pnpm lint reports no errors; its one warning (import order in Image.tsx) was already there.

What should be covered while testing?

  1. Add an Image widget with On click set to Enlarge, an image larger than about 300 px, Width 50% (percentage) and Max height 250 px. Run the app and click the image. The enlarged image is shown at its natural size, not smaller than on the page.
  2. Repeat with only a percentage width, only a max height, and a fixed pixel width. Each time the enlarged image is shown at its natural size.
  3. Use an image larger than the browser window, or make the window small. The enlarged image fits inside the window and keeps its aspect ratio.
  4. Set Show to Thumbnail: the enlarged image is still the full image (no thumb=true in its URL).
  5. Close the lightbox with the close button, the backdrop and Escape.
  6. Check that the image on the page itself is unchanged for each setting.

🤖 Generated with Claude Code

@gjulivan
gjulivan requested a review from a team as a code owner November 4, 2026 12:49
@github-actions

This comment has been minimized.

iobuhov
iobuhov previously approved these changes Nov 5, 2026

@iobuhov iobuhov left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@github-actions

This comment has been minimized.

@gjulivan
gjulivan force-pushed the combobox/fix-lightbox branch from b8f7b8e to 088ba67 Compare November 16, 2026 21:04
@github-actions

This comment has been minimized.

leonardomendix
leonardomendix previously approved these changes Nov 17, 2026
gjulivan and others added 3 commits November 17, 2026 13:33
…-ratio styles

- Give the lightbox image its own class so its max width and height win over
  Atlas's `img.img-thumbnail { max-width: 100% }`, which capped a thumbnail at
  half the window.
- Never show the enlarged image smaller than the image on the page: measure the
  image on click and, when that is larger than the natural size, set a width
  that keeps the aspect ratio and still fits the viewport.
- Drop aspect-ratio, object-fit and object-position from the inline style passed
  to the lightbox image, so it is not cropped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ContentImage and BackgroundImage overwrote the height from
constructStyleObject with getStyle(), which only handled pixels and
percentage and returned "" for viewport, so a height in vh was dropped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@gjulivan
gjulivan force-pushed the combobox/fix-lightbox branch from 26166b3 to 4acea0e Compare November 17, 2026 12:33
@gjulivan
gjulivan enabled auto-merge (rebase) November 17, 2026 12:35
@github-actions

Copy link
Copy Markdown
Contributor

AI Code Review

✅ Approved — no issues found


What was reviewed

File Change
image-web/src/components/Image/Image.tsx Captures the image's size on the page on click. The lightbox now renders LightboxImage instead of cloning the page image.
image-web/src/components/Image/LightboxImage.tsx New component. It strips the page-only sizing styles and sets a width so the enlarged image is never smaller than on the page.
image-web/src/components/Image/ui.tsx Maps the viewport height unit to vh.
image-web/src/ui/Image.scss Shows the lightbox image at its natural size, capped at 90vw × 85vh.
image-web/src/components/__tests__/Image.spec.tsx, LightboxImage.spec.tsx Unit tests for the sizing, style stripping, thumbnail class and viewport height.
image-web/CHANGELOG.md Two "Fixed" entries under Unreleased.

Skipped (out of scope): none

CI: pending: Run code quality check, Plan E2E matrix, sigridci · unrelated failures: security/snyk (external scanner)


Questions

  • The changelog says the enlarged image shows "at its natural size, or at its size on the page when that is larger". The PR description also notes that a fixed pixel width smaller than the image now enlarges it. Do you want the changelog to say this more directly, so app developers expect the new behavior?

Positives

  • The tests cover the regression (percentage width plus max height), the stripped style properties, the thumbnail class and URL, and the size floor.
  • The fix is scoped to the lightbox. The image on the page is untouched, and the other inline styles, alt text and thumbnail class are kept.
  • The changelog entries are written for app developers and follow the repo voice. The viewport height unit fix is covered by tests and consistent with helpers.ts.

@gjulivan
gjulivan merged commit 6c31008 into main Nov 17, 2026
13 of 14 checks passed
@gjulivan
gjulivan deleted the combobox/fix-lightbox branch November 17, 2026 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants