[Help]: scrollSnapList is only returning 'one big slide' #747
-
SummaryI have a carousel set up which appears in a modal. The modal is using Framer Motion's AnimatePresence, and it's rendered conditionally based on if It renders something like this: <AnimatePresence>
{modalOpen && (
<div>{children}</div>
)}
</AnimatePresence> It appears that Embla works, but it's miscalculating the amount of slides. I'm setting it up like this (note I'm using tailwind) const [emblaRef] = useEmblaCarousel({ axis: "y" });
return (
<Modal>
<div ref={emblaRef} className="h-[90vh]">
<div className="flex flex-col">
{slides.map((slide) => (
<div key={slide.key} className="relative flex flex-[0_0_90vh]">...content...</div>
)}
</div>
</div>
</Modal>
) I think it's obvious that Embla isn't able to calculate the sizes of the slides since they're completely hidden until
Hopefully it's something super obvious, but I'd really appreciate some input on this! Thanks :) If applicable, which variants of Embla Carousel are relevant to this question?
Additional informationNo response CodeSandbox example |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
@modulareverything thanks for your question. Could you create a CodeSandbox with a minimal reproduction where you strip unnecessary details? It's not possible to debug fragments of code. Thanks for understanding!
Best, |
Beta Was this translation helpful? Give feedback.
-
Hey @davidjerleke, cheers for the fast response. Yeah, you're right, I wouldn't be able to debug that myself either 😅 Here's a very minimal recreation which seems to be suffering from the same fate: Toggle the modal, then try to swipe the slides up. You should see it slide up and then rest back in the original position. |
Beta Was this translation helpful? Give feedback.
-
@modulareverything This is related to your CSS.
Take a look at this fixed sandbox: |
Beta Was this translation helpful? Give feedback.
@modulareverything This is related to your CSS.
.embla__slide
isflex: 0 0 50vh;
, you shouldn't be dealing withvh
unit here..embla__container
is missingheight
.Take a look at this fixed sandbox:
https://codesandbox.io/p/sandbox/embla-modal-bug-fixed-jfc5wl?file=%2Fsrc%2Fstyles.css%3A13%2C20