Skip to content

Commit

Permalink
fix(components): input-number 0 can not triger change event (#10980)
Browse files Browse the repository at this point in the history
* fix(components): input-number 0 can not triger change event

* fix(components): use isNumber(userInput)

* test(components): change event add input 0 case
  • Loading branch information
StephenKe committed Dec 16, 2022
1 parent a47bf23 commit c39d591
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions packages/components/input-number/__tests__/input-number.test.tsx
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,14 @@ describe('InputNumber.vue', () => {
expect(
wrapper.getComponent(InputNumber).emitted('update:modelValue')
).toHaveLength(2)
await wrapper.find('input').setValue(0)
expect(wrapper.getComponent(InputNumber).emitted('change')).toHaveLength(3)
expect(wrapper.getComponent(InputNumber).emitted().change[2]).toEqual([
0, 2,
])
expect(
wrapper.getComponent(InputNumber).emitted('update:modelValue')
).toHaveLength(4)
})

test('blur-event', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/components/input-number/src/input-number.vue
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ watch(
(value) => {
const userInput = verifyValue(data.userInput)
const newValue = verifyValue(value, true)
if (!userInput || userInput !== newValue) {
if (!isNumber(userInput) && (!userInput || userInput !== newValue)) {
data.currentValue = newValue
data.userInput = null
}
Expand Down

0 comments on commit c39d591

Please sign in to comment.