Skip to content

Carousel v-model goes past last slide in autoplay #515

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

Open
Tofandel opened this issue May 22, 2025 · 0 comments · May be fixed by #516
Open

Carousel v-model goes past last slide in autoplay #515

Tofandel opened this issue May 22, 2025 · 0 comments · May be fixed by #516

Comments

@Tofandel
Copy link
Contributor

Tofandel commented May 22, 2025

Describe the bug
Carousel v-model goes past last slide in autoplay

To Reproduce
Steps to reproduce the behavior:

  1. Create a carousel with 2 slides autoplay and a vModel
  2. Print the vModel
  3. The vModel will go: 0, 1, 2 and stop at 2
  4. But because it's 0 indexed, 2 is out of bounds and an invalid vModel

Expected behavior
The vModel to stay less than 2

Issue seems to be there

let targetIndex = slideIndex
let mappedIndex = slideIndex
prevSlideIndex.value = currentSlideIndex.value
if (!config.wrapAround) {
targetIndex = getNumberInRange({
val: targetIndex,
max: maxSlideIndex.value,
min: minSlideIndex.value,
})
} else {
mappedIndex = mapNumberToRange({
val: targetIndex,
max: maxSlideIndex.value,
min: minSlideIndex.value,
})
}
emit('slide-start', {
slidingToIndex: slideIndex,
currentSlideIndex: currentSlideIndex.value,
prevSlideIndex: prevSlideIndex.value,
slidesCount: slidesCount.value,
})
stopAutoplay()
isSliding.value = true
currentSlideIndex.value = targetIndex
if (mappedIndex !== targetIndex) {
modelWatcher.pause()
}
emit('update:modelValue', mappedIndex)

Image

Mapped index is not modified when no wraparound but vModel is updated to it. This seems wrong. Additionally if the targetIndex is the same as the currentIndex we should abort early

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant