ElemeFE / ElemeFE/mint-ui

[Bug Report] picker组件中计算选择index时由于计算精度丢失导致无法选中

Open
#1,560 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
Vue
Stars
16.4k
Forks
3.5k
PR merge metrics
No merged PRs in 30d

Description

### Mint UI version
2.2.13

### OS/Browsers version
MacOS 10.13.6 / Chrome 73.0.3683.86

### Vue version
2.5.2

### Reproduction Link
[https://elementui.github.io/issue-generator/#/zh-CN?repo=mint](https://elementui.github.io/issue-generator/#/zh-CN?repo=mint)

### Steps to reproduce
正常使用picker

### What is Expected?
可以选中任意选项

### What is actually happening?
部分选项无法选中

原因:
picker组件源码中的translate2Value函数中
var index = -(translate - Math.floor(this.visibleItemCount / 2) * itemHeight) / itemHeight;
index的计算过程发生精度丢失导致index可能等于2.99999999996等类似数值,从而使this.mutatingValues[index]为null,无法返回正常选中的值

解决方法:
this.mutatingValues[Math.round(index)]

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in the picker component at the translate2Value function and reproduce the selection problem using the provided reproduction link. Inspect the index calculation and verify that any selected option, including cases affected by floating-point precision, is returned correctly; confirm the behavior with the picker reproduction.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.