-
-
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
containScroll: 'trimSnaps' unexpected behavior when there is not enough slides in view #507
Comments
Hi @MaxDesignFR, Thank you for your question. The There's nothing wrong with your fix. I guess there are multiple ways to check if the carousel isn't scrollable because of lack of enough content. Another one being: const justifyCenter = this.slider.scrollSnapList().length === 1; Best, |
Thanks for reviewing my post. Your way is actually more concise, way to go! (Edit: actually, I get error You may close the issue if you like. I'll share some feedback though: I am personally a little puzzled about the My use case is a little niche because I add/remove slides, so sometimes there are not enough of them to fill the container space ; but I can imagine having a single slider with 4/5 slides with
I'm just throwing my personal experience using Embla, I trust you are the best judge to decide what's relevant, furthermore I really like what has been done with the library, recent updates are really neat, so until this gets more attention I don't mind using the fix we discussed, it's functional. Thanks for your attention. |
Hi @MaxDesignFR,
I'm sorry, I didn't spell it correctly. It's not ❌ const justifyCenter = this.slider.scollSnapList().length === 1;
✅ const justifyCenter = this.slider.scrollSnapList().length === 1;
Do you mean for this special case or in general? If the latter, watch this: contain-scroll.movNote this in the screen recording:
Have you tried something along these lines? let previousIsScrollable = true
function centerIfNotScrollable(emblaApi) {
const isScrollable = emblaApi.scrollSnapList().length === 1;
if (isScrollable === previousIsScrollable) return;
const containScroll = isScrollable ? 'trimSnaps' : null
previousIsScrollable = isScrollable
emblaApi.reInit({ containScroll });
}
const emblaApi = EmblaCarousel(emblaNode, {
containScroll: 'trimSnaps',
loop: true
});
emblaApi
.on('init', centerIfNotScrollable)
.on('reInit', centerIfNotScrollable)
Devs use this setup sometimes, especially when slide widths are small like 25% or similar. So I don't think we should remove that option. But I agree that maybe
Thanks a lot! The Best, |
Well that's my bad too. I must have copy paste first, hence the I get your point for That said, I remember going through closed issue to find some videos about differences with
This code triggers I'm definitely keeping an eye on the |
I agree and think your reasoning makes sense. I will make
Thanks for the feedback! Yes, it's a challenge to explain how My biggest challenge by far with this library is to find ways to automate things and get rid of repetitive questions about core functionality - especially because I'm the sole dev in this project. I want to offload that kind of repetitive work to focus more on the library core, build more features, plugins and improve the documentation. Bottom line: I have this planned and I'm also hoping that the
Yes, sorry about that. I was pretty tired when writing that and I missed two things:
const justifyCenter = this.slider.scrollSnapList().length === 1;
About the Best, |
Note to self: make |
Make `containScroll: 'trimSnaps'` default
To be released with v8.0.0-rc09. |
@MaxDesignFR the default value for Best, |
Bug is related to
Embla Carousel version
Describe the bug
containScroll: 'trimSnaps'
will align the slides to the left, which I suppose is expected to be centered in some case (see expected behavior).CodeSandbox
justify-content:center
to the container fixes it.Expected behavior
Embla.canScrollPrev()
andEmbla.canScrollNext()
are false, the slides are expected to be centered by default. If one of those is true though, then it is expected to be aligned left, as is right now.Additional context
containScroll: 'trimSnaps'
because sometimes there are not enough slides in the view, and Embla can not enableloop
option, the leading and trailing spaces are not wanted. When adding or removing slides, sometimes bothEmbla.canScrollPrev()
andEmbla.canScrollNext()
are false, and in this case I believe Embla should align center the carousel.Fix I use (dirty?)
Screen capture before fix is applied: https://i.vgy.me/WpzzoW.gif
Screen capture after fix is applied: https://i.vgy.me/m0D51b.gif
The only difference is that when both
Embla.canScrollPrev()
andEmbla.canScrollNext()
are false, the slides are centered instead of aligned left.What I did for that is simple, but it's a bad experience since it feels like a "hack", and I have yet to find a better way. Here is a snippet of code that is self-explanatory:
I did not figure out a native way to align center the slides in this use case. Doing this workaround seems quite bad, can Embla core fix this, or is there a better way to handle this?
The text was updated successfully, but these errors were encountered: