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): optional height #3420

Merged
merged 3 commits into from
Jul 6, 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
5 changes: 5 additions & 0 deletions .changeset/cool-pugs-lay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nextui-org/image": patch
---

fixed missing required `height` property issue
17 changes: 8 additions & 9 deletions packages/components/image/src/use-image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ export function useImage(originalProps: UseImageProps) {
srcSet,
sizes,
crossOrigin,
height,
...otherProps
} = props;

Expand All @@ -122,20 +121,20 @@ export function useImage(originalProps: UseImageProps) {

const domRef = useDOMRef(ref);

const {w} = useMemo(() => {
const {w, h} = useMemo(() => {
return {
w: props.width
? typeof props.width === "number"
? `${props.width}px`
: props.width
: "fit-content",
h: props.height
? typeof props.height === "number"
? `${props.height}px`
: props.height
: "auto",
};
}, [props?.width]);

const h = useMemo(
() => (height ? (typeof height === "number" ? `${height}px` : height) : "auto"),
[height],
);
}, [props?.width, props?.height]);
wingkwong marked this conversation as resolved.
Show resolved Hide resolved

const showFallback = (!src || !isImgLoaded) && !!fallbackSrc;
const showSkeleton = isLoading && !disableSkeleton;
Expand Down Expand Up @@ -168,7 +167,7 @@ export function useImage(originalProps: UseImageProps) {
style: {
// img has `height: auto` by default
// passing the custom height here to override if it is specified
...(height && {height: h}),
...(otherProps?.height && {height: h}),
...props.style,
...otherProps.style,
},
Expand Down