Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(runtime-dom): v-model can update correctly when the element is an input of type number #7004

Merged
merged 42 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
4733a78
fix(compiler-dom):v-model can update correctly when the element is an…
Nov 1, 2022
e2eb414
Merge remote-tracking branch 'origin/main'
Nov 1, 2022
7e6dd13
fix(compiler-dom):added code comment
Nov 1, 2022
cbacf73
fix(runtime-dom):v-model can update correctly when the element is an …
baiwusanyu-c Nov 1, 2022
9dcf950
fix(runtime-dom):added code comment
baiwusanyu-c Nov 1, 2022
8241259
Update packages/runtime-dom/src/directives/vModel.ts
baiwusanyu-c Nov 1, 2022
1eeaf26
fix(runtime-dom):format code
baiwusanyu-c Nov 1, 2022
542a466
fix(runtime-dom): update logical code
baiwusanyu-c Nov 1, 2022
91e95fd
Merge branch 'vuejs:main' into bwsy/fix/vModel
baiwusanyu-c Nov 8, 2022
a40e6ff
Merge branch 'vuejs:main' into bwsy/fix/vModel
baiwusanyu-c Nov 8, 2022
d566a1a
Merge branch 'vuejs:main' into bwsy/fix/vModel
baiwusanyu-c Nov 8, 2022
f379c39
Merge branch 'vuejs:main' into bwsy/fix/vModel
baiwusanyu-c Nov 8, 2022
a2e488a
Merge branch 'vuejs:main' into bwsy/fix/vModel
baiwusanyu-c Nov 11, 2022
ece6bb1
Merge branch 'vuejs:main' into bwsy/fix/vModel
baiwusanyu-c Nov 16, 2022
06dd48b
Merge branch 'vuejs:main' into bwsy/fix/vModel
baiwusanyu-c Dec 2, 2022
80b46b6
Merge branch 'vuejs:main' into bwsy/fix/vModel
baiwusanyu-c Dec 26, 2022
e5096c0
Merge branch 'vuejs:main' into bwsy/fix/vModel
baiwusanyu-c Jan 2, 2023
b5239a7
Merge branch 'vuejs:main' into bwsy/fix/vModel
baiwusanyu-c Jan 9, 2023
0dea42d
Merge branch 'vuejs:main' into bwsy/fix/vModel
baiwusanyu-c Jan 13, 2023
026725e
Merge remote-tracking branch 'origin/main' into bwsy/fix/vModel
baiwusanyu-c Feb 4, 2023
144572b
Merge branch 'vuejs:main' into bwsy/fix/vModel
baiwusanyu-c Feb 6, 2023
83faf60
Merge branch 'main' into bwsy/fix/vModel
baiwusanyu-c Feb 14, 2023
81ee072
Merge branch 'main' into bwsy/fix/vModel
baiwusanyu-c Feb 21, 2023
79031f2
Merge branch 'main' into bwsy/fix/vModel
baiwusanyu-c Feb 22, 2023
d3ca20d
Merge branch 'main' into bwsy/fix/vModel
baiwusanyu-c Mar 17, 2023
89ca9ec
Merge branch 'main' into bwsy/fix/vModel
baiwusanyu-c Mar 20, 2023
afa6e82
Merge branch 'main' into bwsy/fix/vModel
baiwusanyu-c Mar 23, 2023
af3a2c8
Merge branch 'main' into bwsy/fix/vModel
baiwusanyu-c Mar 27, 2023
abb0c48
Merge branch 'main' into bwsy/fix/vModel
baiwusanyu-c Apr 6, 2023
d024d01
Merge branch 'main' into bwsy/fix/vModel
baiwusanyu-c Apr 10, 2023
4445e0d
Merge branch 'main' into bwsy/fix/vModel
baiwusanyu-c Apr 11, 2023
c016ae3
Merge branch 'main' into bwsy/fix/vModel
baiwusanyu-c Apr 14, 2023
5b41f94
Merge branch 'main' into bwsy/fix/vModel
baiwusanyu-c Apr 17, 2023
e51edd7
Merge branch 'main' into bwsy/fix/vModel
baiwusanyu-c Apr 19, 2023
b6d03f4
Merge branch 'main' into bwsy/fix/vModel
baiwusanyu-c Apr 20, 2023
6a20f86
Merge branch 'main' into bwsy/fix/vModel
baiwusanyu-c May 4, 2023
c726752
Merge branch 'main' into bwsy/fix/vModel
baiwusanyu-c May 8, 2023
abbd0bd
Merge branch 'main' into bwsy/fix/vModel
baiwusanyu-c May 16, 2023
d70dee1
Merge branch 'main' into bwsy/fix/vModel
baiwusanyu-c Aug 30, 2023
f7fd92d
Merge branch 'main' into bwsy/fix/vModel
baiwusanyu-c Sep 5, 2023
e2672da
Merge branch 'main' into bwsy/fix/vModel
baiwusanyu-c Oct 20, 2023
2837525
Update vModel.ts
yyx990803 Nov 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions packages/runtime-dom/__tests__/directives/vModel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,61 @@ describe('vModel', () => {
expect(data.value).toEqual(1)
})

// #7003
it('should work with number input and be able to update rendering correctly', async () => {
const setValue1 = function (this: any, value: any) {
this.value1 = value
}
const setValue2 = function (this: any, value: any) {
this.value2 = value
}
const component = defineComponent({
data() {
return { value1: 1.002, value2: 1.002 }
},
render() {
return [
withVModel(
h('input', {
id: 'input_num1',
type: 'number',
'onUpdate:modelValue': setValue1.bind(this)
}),
this.value1
),
withVModel(
h('input', {
id: 'input_num2',
type: 'number',
'onUpdate:modelValue': setValue2.bind(this)
}),
this.value2
)
]
}
})
render(h(component), root)
const data = root._vnode.component.data

const inputNum1 = root.querySelector('#input_num1')!
expect(inputNum1.value).toBe('1.002')

const inputNum2 = root.querySelector('#input_num2')!
expect(inputNum2.value).toBe('1.002')

inputNum1.value = '1.00'
triggerEvent('input', inputNum1)
await nextTick()
expect(data.value1).toBe(1)

inputNum2.value = '1.00'
triggerEvent('input', inputNum2)
await nextTick()
expect(data.value2).toBe(1)

expect(inputNum1.value).toBe('1.00')
})

it('should work with multiple listeners', async () => {
const spy = jest.fn()
const component = defineComponent({
Expand Down
11 changes: 9 additions & 2 deletions packages/runtime-dom/src/directives/vModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,15 @@ export const vModelText: ModelDirective<
}
}
const newValue = value == null ? '' : value
if (el.value !== newValue) {
el.value = newValue
// #7003 v-model can update correctly when the element is an input of type number
if (el.type === 'number' && vnode.type === 'input') {
baiwusanyu-c marked this conversation as resolved.
Show resolved Hide resolved
if (Number(el.value) !== newValue) {
el.value = newValue
}
} else {
if (el.value !== newValue) {
el.value = newValue
}
}
}
}
Expand Down