Skip to content

Rendering sortable-gallery with next.js Image component does not show overlay #180

Answered by igordanchenko
park-onezero asked this question in Q&A
Discussion options

You must be logged in to vote

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:

  1. Add data-id attribute to the next/image image:
<Image
 data-id={photo.src}
 // ...
/>
  1. Modify handleDragStart function in the SortableGallery.tsx:
const image = ref.current?.querySelector(`img[data-id="${photo?.id}"]`);
const padding = image?.parentElement?.parentElement
  ? getComputedStyle(image.parentElement.parentElement).padding
  : undefined;

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@park-onezero
Comment options

Answer selected by park-onezero
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants