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: img SVGs with no dimensions not scaling #629

Merged
merged 1 commit into from
Jul 8, 2024
Merged
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
12 changes: 6 additions & 6 deletions source/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,8 @@ export const getStyleModalImg: GetStyleModalImg = ({
containerWidth: imgRect.width,
hasScalableSrc,
offset,
targetHeight: loadedImgEl?.naturalHeight ?? imgRect.height,
targetWidth: loadedImgEl?.naturalWidth ?? imgRect.width,
targetHeight: loadedImgEl?.naturalHeight || imgRect.height,
targetWidth: loadedImgEl?.naturalWidth || imgRect.width,
})

const styleImgObjectFit = isImgObjectFit
Expand All @@ -484,8 +484,8 @@ export const getStyleModalImg: GetStyleModalImg = ({
objectFit: targetElComputedStyle.objectFit,
objectPosition: targetElComputedStyle.objectPosition,
offset,
targetHeight: loadedImgEl.naturalHeight,
targetWidth: loadedImgEl.naturalWidth,
targetHeight: loadedImgEl?.naturalHeight || imgRect.height,
targetWidth: loadedImgEl?.naturalWidth || imgRect.width,
})
: undefined

Expand All @@ -499,8 +499,8 @@ export const getStyleModalImg: GetStyleModalImg = ({
containerWidth: imgRect.width,
hasScalableSrc,
offset,
targetHeight: loadedImgEl.naturalHeight,
targetWidth: loadedImgEl.naturalWidth,
targetHeight: loadedImgEl?.naturalHeight || imgRect.height,
targetWidth: loadedImgEl?.naturalWidth || imgRect.width,
})
: undefined

Expand Down
20 changes: 15 additions & 5 deletions stories/Img.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const Regular = (props) => (
alt={imgThatWanakaTree.alt}
src={imgThatWanakaTree.src}
height="320"
decoding="async"
loading="lazy"
/>
</Zoom>
Expand All @@ -65,6 +66,7 @@ export const ZoomMargin = (props) => (
alt={imgThatWanakaTree.alt}
src={imgThatWanakaTree.src}
height="320"
decoding="async"
loading="lazy"
/>
</Zoom>
Expand All @@ -84,6 +86,7 @@ export const SmallPortrait = (props) => (
alt={imgTeAraiPoint.alt}
src={imgTeAraiPoint.src}
height="112"
decoding="async"
loading="lazy"
/>
</Zoom>
Expand All @@ -98,7 +101,13 @@ export const SVGSource = (props) => (
<h1>An image with an SVG src</h1>
<div className="mw-600">
<Zoom {...props}>
<img alt={imgNzMap.alt} src={imgNzMap.src} width="150" loading="lazy" />
<img
alt={imgNzMap.alt}
src={imgNzMap.src}
width="150"
decoding="async"
loading="lazy"
/>
</Zoom>
</div>
</main>
Expand Down Expand Up @@ -235,6 +244,7 @@ export const ModalFigureCaption = (props) => (
alt={imgThatWanakaTree.alt}
src={imgThatWanakaTree.src}
height="320"
decoding="async"
loading="lazy"
/>
</Zoom>
Expand Down Expand Up @@ -401,8 +411,8 @@ export const DelayedDisplayNone = (props) => {
alt={imgTekapo.alt}
src={imgTekapo.src}
className={classImg}
decoding="async"
height="320"
decoding="async"
loading="lazy"
/>
</Zoom>
Expand Down Expand Up @@ -442,8 +452,8 @@ export const InlineImage = (props) => (
<img
alt={imgThatWanakaTree.alt}
src={imgThatWanakaTree.src}
decoding="async"
height="320"
decoding="async"
loading="lazy"
/>
</Zoom>
Expand All @@ -466,8 +476,8 @@ export const SwipeToUnzoomDisabled = (props) => (
<img
alt={imgThatWanakaTree.alt}
src={imgThatWanakaTree.src}
decoding="async"
height="320"
decoding="async"
loading="lazy"
/>
</Zoom>
Expand All @@ -494,8 +504,8 @@ export const SwipeToUnzoomThreshold = (props) => (
<img
alt={imgThatWanakaTree.alt}
src={imgThatWanakaTree.src}
decoding="async"
height="320"
decoding="async"
loading="lazy"
/>
</Zoom>
Expand Down