Repository navigation
[WC-3633] fix(image-web): lightbox size for thumbnails, small images and aspect-ratio styles - #2530
Merged
Conversation
…-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>
Contributor
AI Code Review
What was reviewed
Skipped (out of scope): CI: unrelated failures: Positives
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 imgand loads later, so it won. The lightbox sits atleft: 50%, so 100% is half the window.Fix: the lightbox image gets its own class,
mx-image-viewer-lightbox-image, andImage.scssstyles 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,
LightboxImagesetswidth: min(<size on page>px, 90vw, 85vh × aspect ratio), so it still fits the window. Otherwise it is sized byImage.scssalone, as in #2511.3. A custom
aspect-ratioin the Style property reached the enlarged image.Fix:
aspect-ratio,object-fitandobject-positionare 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:
aspect-ratio: 1 / 1; object-fit: cover;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 testpasses (53 tests, new:LightboxImage.spec.tsxand three cases inImage.spec.tsx).pnpm lintreports no errors; its one warning (import order ofclassnamesinImage.tsx) was already there.What should be covered while testing?
aspect-ratio: 1 / 1; object-fit: cover;.🤖 Generated with Claude Code