Rendering sortable-gallery with next.js Image component does not show overlay #180
Answered
by
igordanchenko
park-onezero
asked this question in
Q&A
-
I combined the two examples, but there is a problem that the overlay image does not appear and the image blinks when onDrop. function renderNextImage({ alt = "", title, sizes }: RenderImageProps, { photo, width, height }: RenderImageContext) {
return (
<div
style={{
width: "100%",
position: "relative",
aspectRatio: `${width} / ${height}`,
}}
>
<Image
fill
src={photo}
alt={alt}
title={title}
sizes={sizes}
placeholder={"blurDataURL" in photo ? "blur" : undefined}
/>
</div>
);
}
<SortableGallery
render={{
image: renderNextImage,
}}
gallery={RowsPhotoAlbum}
spacing={4}
photos={photos}
movePhoto={(oldIndex, newIndex) => setPhotos(arrayMove(photos, oldIndex, newIndex))}
/> |
Beta Was this translation helpful? Give feedback.
Answered by
igordanchenko
Aug 29, 2024
Replies: 1 comment 1 reply
-
Thank you for bringing this up. This is happening because You should be able to make the two examples work together with the following modifications:
<Image
data-id={photo.src}
// ...
/>
const image = ref.current?.querySelector(`img[data-id="${photo?.id}"]`);
const padding = image?.parentElement?.parentElement
? getComputedStyle(image.parentElement.parentElement).padding
: undefined; |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
park-onezero
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for bringing this up. This is happening because
SortableGallery
example is unaware of the DOM structure of photos rendered with a custom render function.You should be able to make the two examples work together with the following modifications:
data-id
attribute to thenext/image
image:handleDragStart
function in theSortableGallery.tsx
: