fix(components): [input-number] Fix value decimals miss prop precision (#8587)

* fix(components): [input-number] Fix value decimals miss prop precision
This commit is contained in:
sorry 2022-07-02 15:38:07 +08:00 committed by GitHub
parent 4fe9c2bd6c
commit d20e58ecbb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View File

@ -94,6 +94,22 @@ describe('InputNumber.vue', () => {
expect(wrapper.find('input').element.value).toEqual('4')
})
test('value decimals miss prop precision', async () => {
const num = ref(0.2)
const wrapper = mount(() => (
<InputNumber step-strictly={true} step={0.1} v-model={num.value} />
))
const elInputNumber = wrapper.findComponent({ name: 'ElInputNumber' }).vm
elInputNumber.increase()
await nextTick()
expect(wrapper.find('input').element.value).toEqual('0.3')
num.value = 0.4
await nextTick()
elInputNumber.decrease()
await nextTick()
expect(wrapper.find('input').element.value).toEqual('0.3')
})
describe('precision accuracy 2', () => {
const num = ref(0)
const wrapper = mount(() => (

View File

@ -201,7 +201,7 @@ const verifyValue = (
newVal = isString(valueOnClear) ? { min, max }[valueOnClear] : valueOnClear
}
if (stepStrictly) {
newVal = Math.round(newVal / step) * step
newVal = toPrecision(Math.round(newVal / step) * step, precision)
}
if (!isUndefined(precision)) {
newVal = toPrecision(newVal, precision)