fix(components): step-strictly is true and should keep the initial value and step matching (#18277)

* fix(components): 修复step-strictly为true时初次渲染组件v-model与输入框中显示的值不同的问题

When step strictly is set to true, the initial rendering of component v-model differs from the value
displayed in the input box。See issue # 18275 for details。

closed #18275

* fix: unit test error

* test(components): [input-number] test cases with fixes added
This commit is contained in:
KESHAOYE 2024-09-17 13:36:36 +08:00 committed by GitHub
parent be79242a20
commit 18a77d5829
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 0 deletions

View File

@ -594,4 +594,14 @@ describe('InputNumber.vue', () => {
expect(increase.classes()).toContain('el-icon')
expect(decrease.classes()).toContain('el-icon')
})
// fix: #18275
test('step-strictly is true and should keep the initial value and step matching', () => {
const num = ref(2.6)
const wrapper = mount(() => (
<InputNumber v-model={num.value} stepStrictly step={0.5} />
))
expect(wrapper.find('input').element.value).toBe(num.value.toString())
wrapper.unmount()
})
})

View File

@ -222,6 +222,9 @@ const verifyValue = (
}
if (stepStrictly) {
newVal = toPrecision(Math.round(newVal / step) * step, precision)
if (newVal !== value) {
update && emit(UPDATE_MODEL_EVENT, newVal)
}
}
if (!isUndefined(precision)) {
newVal = toPrecision(newVal, precision)