-
-
Notifications
You must be signed in to change notification settings - Fork 160
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
[Feat]: Changing the carousel active setting resets the slide to first #540
Comments
Hi @hmartiins, Thanks for your bug report. I wouldn’t call this a bug though because it isn’t obvious to me that it should work the way you describe. I think you could argue for both sides. The You can preserve the state yourself like this: // preserve location before changing the active option to false
const preservedLocation = emblaApi.internalEngine().location.get() And apply that value to the container after you’ve deactivated the carousel with translateX(‘${preservedLocation}px’). Best, |
Hi @davidjerleke! I understand what you mean, after creating this issue I took a look at the library code and understood what you meant. However, in my understanding, when changing the state of the active option, it should not reset the carousel to the first slide. But really, this isn't a bug according to the code. It would be cool and very useful if there was an option in the embla api that we could change the value of active without the carousel going back to the first slide. |
Hi @hmartiins, Thank you for your input. Many devs use this option to disable the carousel entirely on desktops and activate the carousel on smaller screens, for example mobile phones. In these cases, removing any styles applied by Embla is necessary. This is how it works today and in practice this means resetting to the first slide. So if we’re to introduce something it should be an additional feature and not replace the current behavior. For example, one way would be to change the type ActiveOptionType = boolean | 'freeze';
true // Carousel is active
false // Carousel is basically destroyed but listening for active option to change
'freeze' // Preserve last scroll location Is this close to what you meant? Best, |
Awesome! 🤩 Yes, it was exactly what I had in mind, and I believe it solves the case I mentioned. |
Thank you for your swift response. I want to be clear so you have the right expectations: I have a lot to do before the stable v8 release so new features will not be prioritized until v8 is released. This means that you have to use the workaround for now if you still want to use this library. The specification for this feature is not a breaking change so it can easily be introduced after the major v8 release. In the meantime, if you can think of a better term than Best, |
@davidjerleke I couldn't think of any better terms, I think |
I have trouble with this bug too. Can't add to slide list new slides in start of array. My carousel go to 1 slide and it looks like a bug. Maybe @hmartiins you can create patch and pr with your decide how to prevent moving to slide 1? Thank you for highlighting this point. |
@Lemaro86 thanks for chiming in. First of all, this isn’t a bug. It’s a feature request. Secondly, when reading your description of the problem you’re most likely doing something wrong and it doesn’t seem to be a bug or related to this. Lastly, what do you mean with this:
? |
Thank you for so fast response. I am sorry. I mean hmartiins. I'll edit my message. If it feature in what version you wanna to add it in roadmap? |
I would love to have this feature too. I keep forgetting that setting Another suggestion would be to introduce an additional option, something like Edit: Oh, I just noticed that the |
I'm having a similar problem. |
@omakise you can preserve the index before applying |
Feature request is related to
Embla Carousel version
Describe the feature request
I have a state, which starts as true, controlling the active option of my carousel.
When scrolling my carousel to a slide other than the initial slide and changing the value of this state to false, my carousel goes back to the first slide
When I change my state value to true again, it returns my carousel to the slide it was before the first state change occurred
CodeSandbox
Steps to reproduce
Expected behavior
Additional context
- Video showing the behavior
The text was updated successfully, but these errors were encountered: