From 3a9798d61feab7f055595e36584209598fa2040e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=89=E4=BB=94?= <1414589221@qq.com> Date: Tue, 19 Dec 2023 13:19:40 +0800 Subject: [PATCH] fix(carousel): trigger incorrect `current-index` value on arrow button click with single image, closes #5130 (#5141) Co-authored-by: 07akioni <07akioni2@gmail.com> --- CHANGELOG.en-US.md | 1 + CHANGELOG.zh-CN.md | 1 + src/carousel/src/Carousel.tsx | 6 +++++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.en-US.md b/CHANGELOG.en-US.md index 3e4f329ddf3..6216d7175d6 100644 --- a/CHANGELOG.en-US.md +++ b/CHANGELOG.en-US.md @@ -9,6 +9,7 @@ - Fix `n-time-picker` formatting (format="HH: mm: ss. SSS") preventing modification of milliseconds in the edit box, closes [#5224](https://github.com/tusen-ai/naive-ui/issues/5224). - Fix `n-notification` notification clips out of screen when screen width is less than 400px wide. - Fix `n-carousel` transition effect incorrect when using the `slide` effect in loop mode with only two elements, closes [#4323](https://github.com/tusen-ai/naive-ui/issues/4323). +- 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 2acf99429d8..50dc1b788b1 100644 --- a/CHANGELOG.zh-CN.md +++ b/CHANGELOG.zh-CN.md @@ -9,6 +9,7 @@ - 修复 `n-time-picker` 时间选择器格式化(`format="HH:mm:ss.SSS"`)后无法在编辑框内修改毫秒数的问题,关闭 [#5224](https://github.com/tusen-ai/naive-ui/issues/5224) - 修复 `n-notification` 通知在屏幕宽度小于 400px 的时候溢出屏幕 - 修复 `n-carousel` 在只有两个元素时,过渡效果为 `slide` 且循环播放时过渡效果有问题,关闭 [#4323](https://github.com/tusen-ai/naive-ui/issues/4323) +- 修复 `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 4c5364dc400..b7302973376 100644 --- a/src/carousel/src/Carousel.tsx +++ b/src/carousel/src/Carousel.tsx @@ -164,7 +164,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')