Dynamic loop && enabled state #365
-
Hi. when items.length > current slidesPerView - enable loop and show navigation Actual Behavior I have similar issue with I use it in react, as part of [https://mantine.dev/others/carousel/](Mantine ui library) Thanks for any ideas how to solve my goal. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi @7iomka, Thanks for your question. Before you try this solution you need to ask the Mantine team to bump the About the solution. I'm not quite sure I'm following but if I understand you correctly, you should be able to set: const options = {
slidesToScroll: 'auto'
} Read more about how About the following logic:
You need to access the Embla instance as demonstrated in the Mantine docs to achieve this. Here's how you can toggle the carousel active: function toggleActiveWhenScrollable() {
const isScrollable = embla.internalEngine().slideLooper.canLoop()
embla.reInit({ active: isScrollable })
}
embla.on('resize', toggleActiveWhenScrollable)
toggleActiveWhenScrollable() ...or with React: const toggleActiveWhenScrollable = useCallback(() => {
if (!embla) return
const isScrollable = embla.internalEngine().slideLooper.canLoop()
embla.reInit({ active: isScrollable })
}, [embla])
useEffect(() => {
if (!embla) return
toggleActiveWhenScrollable()
embla.on('resize', toggleActiveWhenScrollable)
}, [embla, toggleActiveWhenScrollable]) I hope this helps you on the right track. Best, |
Beta Was this translation helpful? Give feedback.
Hi @7iomka,
Thanks for your question. Before you try this solution you need to ask the Mantine team to bump the
embla-carousel-react
version to the latest. Because v7.0.0 had a serious bug that was fixed in v7.0.1.About the solution. I'm not quite sure I'm following but if I understand you correctly, you should be able to set:
Read more about how
slidesToScroll
works here. And make sure to pass the options as demonstrated in the Mantine docs because Mantine adds a layer on top of the raw carousel API.About the following logic: