Skip to content

[WC-3633] fix(image-web): lightbox size for thumbnails, small images and aspect-ratio styles - #2530

Merged
gjulivan merged 1 commit into
combobox/fix-lightboxfrom
image/fix-lightbox-review-issues
Nov 13, 2026
Merged

gjulivan merged 1 commit into
combobox/fix-lightboxfrom
image/fix-lightbox-review-issues

Conversation

@gjulivan

Copy link
Copy Markdown
Collaborator

Pull request type

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


Description

Follow-up to #2511 (WC-3633), for the three issues QA found in it. Base branch is combobox/fix-lightbox, so this PR shows only the changes on top of #2511.

1. Show = Thumbnail: a large image was capped at half the window.
Atlas's img.img-thumbnail { max-width: 100% } has the same specificity as .mx-image-viewer-lightbox img and loads later, so it won. The lightbox sits at left: 50%, so 100% is half the window.
Fix: the lightbox image gets its own class, mx-image-viewer-lightbox-image, and Image.scss styles it as .mx-image-viewer-lightbox .mx-image-viewer-lightbox-image, which is more specific. The limits are now CSS variables on .mx-image-viewer-lightbox (--mx-image-viewer-lightbox-max-width: 90vw, --mx-image-viewer-lightbox-max-height: 85vh).

2. Enlarge could make the image smaller than on the page.
#2511 showed the enlarged image at its natural size, so a 400×300 image shown at 560×420 shrank to 400×300 when enlarged.
Fix: on click, the size of the image on the page is measured. The enlarged image is shown at its natural size, or at its size on the page when that is larger, keeping the natural aspect ratio. When it has to be larger than its natural size, LightboxImage sets width: min(<size on page>px, 90vw, 85vh × aspect ratio), so it still fits the window. Otherwise it is sized by Image.scss alone, as in #2511.

3. A custom aspect-ratio in the Style property reached the enlarged image.
Fix: aspect-ratio, object-fit and object-position are also removed from the inline style passed to the lightbox image, together with width, height and their min/max. They only make sense for the box the image has on the page.

The lightbox image is now its own component, src/components/Image/LightboxImage.tsx. The changelog entry from #2511 now says that the enlarged image is not smaller than the image on the page.

Not changed here (also on main, not caused by #2511): Escape in a popup closes both the lightbox and the popup, and a Height in viewport units (vh) is never applied to the image on the page.

Verified

Mendix 11.16.1 app with static images of 2400×1600, 400×300 and 160×120 px, measured with Playwright in Chromium. Before = #2511 head (803d3d09), after = this branch.

1440 × 900 window:

Image widget settings On page Before After
2400×1600, Thumbnail, Width 50% 670×450 720×483 1143×765
2400×1600, Full image, Width auto, max height 250 px 375×250 1148×765 1148×765
400×300, Width 560 px 560×420 400×300 560×420
160×120, Width 600 px 600×450 160×120 600×450
160×120, Width 480 px 480×360 160×120 480×360
160×120, Width 400 px 400×300 160×120 400×300
400×300, Width 300 px, Style aspect-ratio: 1 / 1; object-fit: cover; 300×300 400×400, cropped 400×300
400×300, Width 50%, max height 250 px 670×250 400×300 670×503
400×300, Width 120 px 120×90 400×300 400×300

400 × 300 window: the thumbnail case goes from 200×137 to 360×243, and the aspect-ratio case from 255×255 (cropped) to 340×255. Every enlarged image is inside the window, without cropping or stretching.

pnpm test passes (53 tests, new: LightboxImage.spec.tsx and three cases in Image.spec.tsx). pnpm lint reports no errors; its one warning (import order of classnames in Image.tsx) was already there.

What should be covered while testing?

  1. The three QA cases above: Thumbnail with a large image at Width 50%, a small image at a fixed width larger than the image, and Style aspect-ratio: 1 / 1; object-fit: cover;.
  2. The cases from [WC-3633] fix: image lightbox inherit image sizing #2511: Width 50% with max height 250 px, and Width 120 px. The enlarged image is shown at its natural size.
  3. Make the window small: each enlarged image fits inside it and keeps its aspect ratio.

🤖 Generated with Claude Code

…-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>
@gjulivan
gjulivan requested a review from a team as a code owner November 13, 2026 14:26
@github-actions

Copy link
Copy Markdown
Contributor

AI Code Review

✅ Approved — no issues found


What was reviewed

File Change
image-web/src/components/Image/LightboxImage.tsx New lightbox image component. It strips page-only styles (including aspect-ratio, object-fit and object-position). It sets a min(...) width when the image on the page is larger than the natural size.
image-web/src/components/Image/Image.tsx Measures the image on the page on click and passes it to LightboxImage as minSize.
image-web/src/ui/Image.scss Lightbox image gets its own class, which is more specific than Atlas img.img-thumbnail. The size limits are now CSS variables.
image-web/src/components/__tests__/Image.spec.tsx, LightboxImage.spec.tsx New unit tests for the style stripping, the thumbnail class and the minimum size.
image-web/CHANGELOG.md The existing Unreleased entry now says the enlarged image is not smaller than the image on the page.

Skipped (out of scope): dist/, pnpm-lock.yaml

CI: unrelated failures: security/snyk (external scanner; the Snyk code and license checks passed, and the PR changes no dependencies) · pending: AI Code Review


Positives

  • The size logic is a pure function, getLightboxImageWidth. It returns undefined when the natural size is large enough, so the SCSS alone sizes the image. The unit tests cover this.
  • The CSS variables keep the viewport limits in one place. The min() width reuses them, so the enlarged image fits the window.
  • The changelog entry describes widget behavior only, and the tests cover the new branches, including the cropped aspect-ratio case.

@gjulivan
gjulivan merged commit 4db808b into combobox/fix-lightbox Nov 13, 2026
4 of 5 checks passed
@gjulivan
gjulivan deleted the image/fix-lightbox-review-issues branch November 13, 2026 14:32
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.

1 participant