2
2
3
3
import { extend , toNumber } from 'shared/util'
4
4
5
- // check platforms/web/util/attrs.js acceptValue
6
- declare type acceptValueElm = HTMLInputElement | HTMLSelectElement | HTMLOptionElement
7
-
8
5
function updateDOMProps ( oldVnode : VNodeWithData , vnode : VNodeWithData ) {
9
6
if ( ! oldVnode . data . domProps && ! vnode . data . domProps ) {
10
7
return
@@ -32,13 +29,19 @@ function updateDOMProps (oldVnode: VNodeWithData, vnode: VNodeWithData) {
32
29
if ( vnode . children ) vnode . children . length = 0
33
30
if ( cur === oldProps [ key ] ) continue
34
31
}
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
+ }
35
38
if ( key === 'value' ) {
36
39
// store value as _value as well since
37
40
// non-string values will be stringified
38
41
elm . _value = cur
39
42
// avoid resetting cursor position when value is the same
40
43
const strCur = cur == null ? '' : String ( cur )
41
- if ( needUpdateValue ( elm , vnode , strCur ) ) {
44
+ if ( shouldUpdateValue ( elm , vnode , strCur ) ) {
42
45
elm . value = strCur
43
46
}
44
47
} else {
@@ -47,12 +50,21 @@ function updateDOMProps (oldVnode: VNodeWithData, vnode: VNodeWithData) {
47
50
}
48
51
}
49
52
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
+ }
56
68
return false
57
69
}
58
70
0 commit comments