Skip to content

Commit bbc07af

Browse files
ktsnyyx990803
authored andcommitted
allow to initialize value attribute to 0 (#3334)
1 parent 9cbe4a3 commit bbc07af

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/platforms/web/runtime/modules/dom-props.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ function updateDOMProps (oldVnode: VNodeWithData, vnode: VNodeWithData) {
2222
// non-string values will be stringified
2323
elm._value = cur
2424
// avoid resetting cursor position when value is the same
25-
if (elm.value != cur) { // eslint-disable-line
26-
elm.value = cur
25+
const strCur = cur == null ? '' : String(cur)
26+
if (elm.value !== strCur) {
27+
elm.value = strCur
2728
}
2829
} else {
2930
elm[key] = cur

test/unit/modules/vdom/modules/props.spec.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,10 @@ describe('vdom domProps module', () => {
2323
const elm = patch(vnode1, vnode2)
2424
expect(elm.src).toBeUndefined()
2525
})
26+
27+
it('should initialize the elements value to zero', () => {
28+
const vnode = new VNode('input', { domProps: { value: 0 }})
29+
const elm = patch(null, vnode)
30+
expect(elm.value).toBe('0')
31+
})
2632
})

0 commit comments

Comments
 (0)