Skip to content

Commit 36a7861

Browse files
J-MichalekJakubvercel[bot]
authored
fix(Carousel): consistent stopOnInteraction behavior (#5489)
Co-authored-by: Jakub <[email protected]> Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
1 parent f10b8e1 commit 36a7861

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/runtime/components/Carousel.vue

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,22 @@ const rootProps = useForwardProps(reactivePick(props, 'active', 'align', 'breakp
163163
const prevIcon = computed(() => props.prevIcon || (dir.value === 'rtl' ? appConfig.ui.icons.arrowRight : appConfig.ui.icons.arrowLeft))
164164
const nextIcon = computed(() => props.nextIcon || (dir.value === 'rtl' ? appConfig.ui.icons.arrowLeft : appConfig.ui.icons.arrowRight))
165165
166+
const stopAutoplayOnInteraction = computed(() => {
167+
if (typeof props.autoplay === 'boolean') {
168+
return true
169+
}
170+
171+
return props.autoplay.stopOnInteraction ?? true
172+
})
173+
174+
const stopAutoScrollOnInteraction = computed(() => {
175+
if (typeof props.autoScroll === 'boolean') {
176+
return true
177+
}
178+
179+
return props.autoScroll.stopOnInteraction ?? true
180+
})
181+
166182
const ui = computed(() => tv({ extend: tv(theme), ...(appConfig.ui?.carousel || {}) })({
167183
orientation: props.orientation
168184
}))
@@ -223,12 +239,26 @@ watch(options, () => {
223239
emblaApi.value?.reInit(options.value, plugins.value)
224240
}, { flush: 'post' })
225241
242+
function stopOnInteraction() {
243+
if (stopAutoplayOnInteraction.value) {
244+
emblaApi.value?.plugins().autoplay?.stop()
245+
}
246+
247+
if (stopAutoScrollOnInteraction.value) {
248+
emblaApi.value?.plugins().autoScroll?.stop()
249+
}
250+
}
251+
226252
function scrollPrev() {
227253
emblaApi.value?.scrollPrev()
254+
stopOnInteraction()
228255
}
256+
229257
function scrollNext() {
230258
emblaApi.value?.scrollNext()
259+
stopOnInteraction()
231260
}
261+
232262
function scrollTo(index: number) {
233263
emblaApi.value?.scrollTo(index)
234264
}

0 commit comments

Comments
 (0)