Skip to content

Commit

Permalink
fix(components): [input-number] Fix value decimals miss prop precision (
Browse files Browse the repository at this point in the history
#8587)

* fix(components): [input-number] Fix value decimals miss prop precision
  • Loading branch information
so11y committed Jul 2, 2022
1 parent 4fe9c2b commit d20e58e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions packages/components/input-number/__tests__/input-number.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => (
Expand Down
2 changes: 1 addition & 1 deletion packages/components/input-number/src/input-number.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d20e58e

Please sign in to comment.