22
33import { extend , toNumber } from 'shared/util'
44
5+ // check platforms/web/util/attrs.js acceptValue
6+ declare type acceptValueElm = HTMLInputElement | HTMLSelectElement | HTMLOptionElement
7+
58function updateDOMProps ( oldVnode : VNodeWithData , vnode : VNodeWithData ) {
69 if ( ! oldVnode . data . domProps && ! vnode . data . domProps ) {
710 return
@@ -35,10 +38,7 @@ function updateDOMProps (oldVnode: VNodeWithData, vnode: VNodeWithData) {
3538 elm . _value = cur
3639 // avoid resetting cursor position when value is the same
3740 const strCur = cur == null ? '' : String ( cur )
38- if ( ! elm . composing && (
39- ( document . activeElement !== elm && elm . value !== strCur ) ||
40- isValueChanged ( vnode , strCur )
41- ) ) {
41+ if ( needUpdateValue ( elm , vnode , strCur ) ) {
4242 elm . value = strCur
4343 }
4444 } else {
@@ -47,7 +47,20 @@ function updateDOMProps (oldVnode: VNodeWithData, vnode: VNodeWithData) {
4747 }
4848}
4949
50- function isValueChanged ( vnode : VNodeWithData , newVal : string ) : boolean {
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
56+ return false
57+ }
58+
59+ function isDirty ( elm : acceptValueElm , checkVal : string ) : boolean {
60+ return document . activeElement !== elm && elm . value !== checkVal
61+ }
62+
63+ function isInputChanged ( vnode : VNodeWithData , newVal : string ) : boolean {
5164 const value = vnode . elm . value
5265 const modifiers = vnode . elm . _vModifiers // injected by v-model runtime
5366 if ( ( modifiers && modifiers . number ) || vnode . elm . type === 'number' ) {
0 commit comments