-
-
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
[Bug]: UI issues when removing slides #720
Comments
It works "correctly" (at least no empty space and in middle position) until rc17. Error appears at rc18. |
@sshmaxime thank you for your bug request. As you say, it shouldn't stop with empty space in middle of the transition. It should hard reset, meaning that it should terminate any ongoing transitions and snap into place at once. So that part is a bug. About the other thing: There's no promise from the Embla side that it should remove slides smoothly. Just to set the expectations right. I'll investigate this when possible. Best, |
Hey @davidjerleke , thanks for the reply. Regarding the smooth animation on remove, well I guess that's totally fair. That being said, on Just so you know, adding the ability to smoothly add and remove items would bring That being said, thanks for investigating the issue. |
That's becuase v8 is automatically listening to changes in slide sizes and added/removed slide nodes. Which is what most of the devs out there want. However, you can opt out of the default auto import { EngineType } from 'embla-carousel/components/Engine';
function EmblaCarousel(props) {
const { options } = props
const [emblaRef, emblaApi] = useEmblaCarousel({
...options,
watchSlides: (emblaApi) => {
const reloadEmbla = (): void => {
const oldEngine = emblaApi.internalEngine();
emblaApi.reInit();
const newEngine = emblaApi.internalEngine();
const copyEngineModules: (keyof EngineType)[] = ['location', 'target', 'scrollBody'];
copyEngineModules.forEach(engineModule => {
Object.assign(newEngine[engineModule], oldEngine[engineModule]);
});
newEngine.translate.to(oldEngine.location.get());
const { index } = newEngine.scrollTarget.byDistance(0, false);
newEngine.index.set(index);
newEngine.animation.start();
};
reloadEmbla();
return false;
},
});
// ...
}
As demonstrated above, it's definitely possible. Especially for simple use cases. The problem with supporting a feature like that is that there's no way to write tests to cover all scenarios that can happen (think about the number of options, methods and events Embla has, and then think about how many combinations are possible). Because devs do all sorts of stuff that will break that, so I don't want a bunch of "false" bug reports where people claim the library is broken because it can't do magic to patch all their crazy cases. Best, |
Thanks a lot, that works really well ! That being said, that looks way too custom to be in our codebase. Don't you really think that it could be in the codebase as an option ? That'd be lovely. Although, as you said, seems like there is a problem with supporting a feature like that, so idk. |
@sshmaxime at the end of the day, I'm maintaining this library and I simply don't have time to handle a lot of "false" bug reports as mentioned in my earlier comment:
But thank you for your ideas anyway. And thanks for reporting this bug ⭐! I found the culprit and will merge the bug fix soon. Best, |
[Bug]: UI issues when removing slides
Version
v8.0.0-rc21
CodeSandbox
https://codesandbox.io/p/sandbox/embla-carousel-default-react-forked-ccnhsf?file=%2Fsrc%2Fjs%2Findex.tsx
What browsers are you seeing the problem on?
Google Chrome
Steps to reproduce
The bug occurs when I remove items from the Carousel before the Carousel Item has completely appeared on screen. Or when I remove items before the Carousel has completely scrolled.
Screen.Recording.2024-01-29.at.10.18.31.mov
Expected Behavior
I should be able to remove Carousel's item smoothly without UI bugs.
Additional Context
No response
Which variants of Embla Carousel are you using?
Before submitting
The text was updated successfully, but these errors were encountered: