Skip to content
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

Wrong index ‘-2’ in clicking left arrow when carousel contains only 1 image #5130

Closed
Chiaki-meow opened this issue Aug 3, 2023 · 0 comments · Fixed by #5141
Closed
Labels
untriaged need to sort

Comments

@Chiaki-meow
Copy link

TuSimple/naive-ui version (版本)

2.34.3

Vue version (Vue 版本)

3.3.4

Browser and its version (浏览器及其版本)

Chrome(89.0.4389.128)

System and its version (系统及其版本)

MacOS(11.2.3)

Node version (Node 版本)

Reappearance link (重现链接)

https://codesandbox.io/embed/friendly-surf-7qlgzq?fontsize=14&hidenavigation=1&theme=dark

Reappearance steps (重现步骤)

Click left arrow, and console will show that currentIndex has been changed to -2, and it cannot be changed or reseted.
点击向左切换图片,在控制台里可以看到currentIndex变成了-2,并且此时点击向左向右切换按钮都不能更改currentIndex

Expected results (期望的结果)

click left arrow, currentIndex cannot change(maybe it was -1 when there is only one image?)

Actual results (实际的结果)

click left arrow, currentIndex changed to -2, and cannot be changed.

Remarks (补充说明)

Maybe it is a good way to avoid this bug by:
When the number of images is one, hide the arrow by:
:show-arrow="images.length > 1"
:)
And the right arrow doesn't has this bug! Only the left one.

我现在解决这个bug的方式是在carousel中引入 :show-arrow="images.length > 1" 去动态判断图片的数量来控制按钮的显隐,因为我觉得如果不点这个左侧切换按键就应该不会有这个bug。但是可能对于这种静态元素不太好用!
在一张图的时候点击右侧切换是不会有问题的,index也不会改变。

@github-actions github-actions bot added the untriaged need to sort label Aug 3, 2023
jizai1125 added a commit to jizai1125/naive-ui that referenced this issue Aug 8, 2023
jizai1125 added a commit to jizai1125/naive-ui that referenced this issue Aug 15, 2023
jizai1125 added a commit to jizai1125/naive-ui that referenced this issue Aug 15, 2023
07akioni added a commit that referenced this issue Dec 19, 2023
…n click with single image, closes #5130 (#5141)

Co-authored-by: 07akioni <07akioni2@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
untriaged need to sort
Projects
None yet
1 participant