Skip to content

Commit 3619318

Browse files
committed
avoid checked state being overwritten before change event trigger (fix #4521)
1 parent 92ad0bd commit 3619318

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

Diff for: src/platforms/web/runtime/modules/dom-props.js

+22-10
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
import { extend, toNumber } from 'shared/util'
44

5-
// check platforms/web/util/attrs.js acceptValue
6-
declare type acceptValueElm = HTMLInputElement | HTMLSelectElement | HTMLOptionElement
7-
85
function updateDOMProps (oldVnode: VNodeWithData, vnode: VNodeWithData) {
96
if (!oldVnode.data.domProps && !vnode.data.domProps) {
107
return
@@ -32,13 +29,19 @@ function updateDOMProps (oldVnode: VNodeWithData, vnode: VNodeWithData) {
3229
if (vnode.children) vnode.children.length = 0
3330
if (cur === oldProps[key]) continue
3431
}
32+
// #4521: if a click event triggers update before the change event is
33+
// dispatched on a checkbox/radio input, the input's checked state will
34+
// be reset and fail to trigger another update.
35+
if (key === 'checked' && !isDirty(elm, cur)) {
36+
continue
37+
}
3538
if (key === 'value') {
3639
// store value as _value as well since
3740
// non-string values will be stringified
3841
elm._value = cur
3942
// avoid resetting cursor position when value is the same
4043
const strCur = cur == null ? '' : String(cur)
41-
if (needUpdateValue(elm, vnode, strCur)) {
44+
if (shouldUpdateValue(elm, vnode, strCur)) {
4245
elm.value = strCur
4346
}
4447
} else {
@@ -47,12 +50,21 @@ function updateDOMProps (oldVnode: VNodeWithData, vnode: VNodeWithData) {
4750
}
4851
}
4952

50-
function needUpdateValue (elm: acceptValueElm, vnode: VNodeWithData, checkVal: string): boolean {
51-
// inputing
52-
if (elm.composing) return false
53-
if (elm.tagName.toLowerCase() === 'option') return true
54-
if (isDirty(elm, checkVal)) return true
55-
if (isInputChanged(vnode, checkVal)) return true
53+
// check platforms/web/util/attrs.js acceptValue
54+
type acceptValueElm = HTMLInputElement | HTMLSelectElement | HTMLOptionElement
55+
56+
function shouldUpdateValue (
57+
elm: acceptValueElm,
58+
vnode: VNodeWithData,
59+
checkVal: string
60+
): boolean {
61+
if (!elm.composing && (
62+
vnode.tag === 'option' ||
63+
isDirty(elm, checkVal) ||
64+
isInputChanged(vnode, checkVal)
65+
)) {
66+
return true
67+
}
5668
return false
5769
}
5870

0 commit comments

Comments
 (0)