mirror of
https://github.com/element-plus/element-plus.git
synced 2025-02-17 11:49:41 +08:00
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:
parent
be79242a20
commit
18a77d5829
@ -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()
|
||||
})
|
||||
})
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user