From dc4f8f9d101c3eb1ed6258137f0efdc3b879de4d Mon Sep 17 00:00:00 2001 From: jizai1125 <1414589221@qq.com> Date: Tue, 15 Aug 2023 13:51:50 +0800 Subject: [PATCH] fix(carousel): trigger incorrect `current-index` value on arrow button click with single image, closes #5130 --- CHANGELOG.en-US.md | 1 + CHANGELOG.zh-CN.md | 1 + src/carousel/src/Carousel.tsx | 8 ++++++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.en-US.md b/CHANGELOG.en-US.md index 8a3eab7b38f..285396824b3 100644 --- a/CHANGELOG.en-US.md +++ b/CHANGELOG.en-US.md @@ -33,6 +33,7 @@ - Fix rapid clicks on `n-date-input`'s buttons triggering a text select for the rest of the website. - Fix `n-auto-complete`'s autocomplete menu's unexpected open when clicking the clear icon with the input not focused, closes [#4658](https://github.com/tusen-ai/naive-ui/issues/4658). - Fix `n-input`'s `on-keyup` prop type, closes [#5101](https://github.com/tusen-ai/naive-ui/issues/5101) +- Fix `n-carousel` trigger incorrect `current-index` value on arrow button click with single image, closes [#5130](https://github.com/tusen-ai/naive-ui/issues/5130). ### Features diff --git a/CHANGELOG.zh-CN.md b/CHANGELOG.zh-CN.md index 82aa0fd87da..2970076d5bf 100644 --- a/CHANGELOG.zh-CN.md +++ b/CHANGELOG.zh-CN.md @@ -33,6 +33,7 @@ - 修复 `n-date-input` 的按钮快速点击时网站其余文本会被选中 - 修复 `n-auto-complete` 在未聚焦状态下点击清除按钮时补全菜单意外打开的问题,关闭 [#4658](https://github.com/tusen-ai/naive-ui/issues/4658) - 修复 `n-input` 属性 `on-keyup` 类型,关闭 [#5101](https://github.com/tusen-ai/naive-ui/issues/5101) +- 修复 `n-carousel` 在只有一张图片时点击箭头切换按钮触发的 `current-index` 值不正确,关闭 [#5130](https://github.com/tusen-ai/naive-ui/issues/5130) ### Features diff --git a/src/carousel/src/Carousel.tsx b/src/carousel/src/Carousel.tsx index 5dddb6f5354..5514bc24c7d 100644 --- a/src/carousel/src/Carousel.tsx +++ b/src/carousel/src/Carousel.tsx @@ -60,7 +60,7 @@ const transitionProperties = [ ] as const type TransitionStyle = Partial< -Pick +Pick > export const carouselProps = { @@ -163,7 +163,11 @@ export default defineComponent({ const duplicatedableRef = computed( // duplicate the copy operation in `slide` mode, // because only its DOM is sequence layout - () => props.loop && props.slidesPerView === 1 && sequenceLayoutRef.value + () => + props.loop && + props.slidesPerView === 1 && + sequenceLayoutRef.value && + totalViewRef.value > 1 ) // user wants to control the transition animation const userWantsControlRef = computed(() => props.effect === 'custom')