-
-
Notifications
You must be signed in to change notification settings - Fork 193
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
Add watchResize
and watchSlides
options
#159
Comments
Hi EJ (@ej-mitchell), Thank you for the clear issue description. I can't be 100% sure because I don't have access to your full setup, but I don't think this is a bug. I think this is happening because one of the following reasons:
Embla Carousel has no internal mechanism for picking up any changes in slides. This has to be done manually by telling Embla to reinitialize. The reason why it works when you resize the window is because Embla automatically calls If this is happening because of reason useEffect(() => {
if (!embla) return
embla.reInit() // If the slides prop changes, pick it up
}, [
embla,
slides /* Add slides as a dependency to trigger this when the prop changes. If you're mapping the children prop to slides, you can add children to the dependency array instead. */
]) If it's happening because of reason const [carouselReady, setCarouselReady] = useState(false)
return (
...
<OverflowContainer ref={carouselReady ? carouselRef : null}>
<FlexContainer>{slideVideos}</FlexContainer>
</OverflowContainer>
...
) Let me know if it helps. Best, |
Thank you so much, @davidjerleke! This was a lovely and concise answer. I will give that a go. 😸 I will close the issue, too since this is not a bug. |
@ej-mitchell let me know how it goes when you've tried my suggestions 👍. |
It worked 😻 thank you! (I had a hunch that it was scenario |
Thanks for confirming @ej-mitchell 👍. Enjoy! |
Sorry to bring this back up @davidjerleke but do you know if there's a similar solution for Vue v3? |
Hi @richgcook, Thank you for your question. You didn't provide any details with your question?
Please note that I have very little experience with Vue so you are probably better off solving this instead of me. But what you need to do is the following: As soon as the slide nodes inside the container change, run this: if (emblaApi.value) emblaApi.value.reInit() I hope it helps. Best, |
Thanks @davidjerleke I opened up a separate issue for this to supply some more details... |
Hi guys, (@ej-mitchell, @richgcook, @DarceyLloyd and more...), The problemDevs using any of the Embla Carousel wrappers like
I'm getting a lot of "false" bug reports about this:
...to mention a few. Additionally, devs using Embla in modals are having trouble misplaced scroll snaps (because you have to run Proposed solutionsI'm suggesting using MutationObserver to solve this and listen for I can think of two solutions: 1. Create a plugin called
|
For any future devs running into this issue, I was able to solve it in React with the help of @react-hook/resize-observer going off of @davidjerleke's observer idea:
In my case, the issue was showing a loading screen before showing the carousel, which was causing the initial size of slides to be 0. The resize observer automatically calls |
watchResize
and watchSlides
options
Feature specification
|
@ej-mitchell, @emjayschoen, @richgcook this feature has been released with v8.0.0-rc01. |
I am still facing this issue and I am using the version I tried all the different ways to solve this as mentioned in the above suggestions but somehow it is still the same. Anyone else still facing this issue? |
Bug is related to
Embla Carousel version
Describe the bug
embla
(which is set touseEmblaCarousel()
) before I do the resizing, the object is notnull
orundefined
.scrollNext
/scrollPrev
methods to not work.CodeSandbox
Steps to reproduce
Expected behavior
Thank you! Let me know if there's anything else I can provide... If this weren't a client project, I would have gifs and other accompanying pieces for you. :( Apart from this strange issue, I've loved using Embla so far!
The text was updated successfully, but these errors were encountered: