Merge pull request #1871 from pygy/fix-1870
Don't update textarea.value if the `DOM.value === vdom.value !== old.value`, Fix #1870
This commit is contained in:
commit
c9186bcdec
4 changed files with 64 additions and 7 deletions
|
|
@ -483,7 +483,7 @@ module.exports = function($window) {
|
||||||
if (key === "value") {
|
if (key === "value") {
|
||||||
var normalized = "" + value // eslint-disable-line no-implicit-coercion
|
var normalized = "" + value // eslint-disable-line no-implicit-coercion
|
||||||
//setting input[value] to same value by typing on focused element moves cursor to end in Chrome
|
//setting input[value] to same value by typing on focused element moves cursor to end in Chrome
|
||||||
if (vnode.tag === "input" && vnode.dom.value === normalized && vnode.dom === $doc.activeElement) return
|
if ((vnode.tag === "input" || vnode.tag === "textarea") && vnode.dom.value === normalized && vnode.dom === $doc.activeElement) return
|
||||||
//setting select[value] to same value while having select open blinks select dropdown in Chrome
|
//setting select[value] to same value while having select open blinks select dropdown in Chrome
|
||||||
if (vnode.tag === "select") {
|
if (vnode.tag === "select") {
|
||||||
if (value === null) {
|
if (value === null) {
|
||||||
|
|
|
||||||
|
|
@ -288,6 +288,43 @@ o.spec("attributes", function() {
|
||||||
|
|
||||||
// o(b.dom.value).equals("")
|
// o(b.dom.value).equals("")
|
||||||
})
|
})
|
||||||
|
o("isn't set when equivalent to the previous value and focused", function() {
|
||||||
|
var $window = domMock({spy: o.spy})
|
||||||
|
var root = $window.document.body
|
||||||
|
var render = vdom($window).render
|
||||||
|
|
||||||
|
var a = {tag: "textarea"}
|
||||||
|
var b = {tag: "textarea", attrs: {value: "1"}}
|
||||||
|
var c = {tag: "textarea", attrs: {value: "1"}}
|
||||||
|
var d = {tag: "textarea", attrs: {value: 1}}
|
||||||
|
var e = {tag: "textarea", attrs: {value: 2}}
|
||||||
|
|
||||||
|
render(root, [a])
|
||||||
|
var spies = $window.__getSpies(a.dom)
|
||||||
|
a.dom.focus()
|
||||||
|
|
||||||
|
o(spies.valueSetter.callCount).equals(0)
|
||||||
|
|
||||||
|
render(root, [b])
|
||||||
|
|
||||||
|
o(b.dom.value).equals("1")
|
||||||
|
o(spies.valueSetter.callCount).equals(1)
|
||||||
|
|
||||||
|
render(root, [c])
|
||||||
|
|
||||||
|
o(c.dom.value).equals("1")
|
||||||
|
o(spies.valueSetter.callCount).equals(1)
|
||||||
|
|
||||||
|
render(root, [d])
|
||||||
|
|
||||||
|
o(d.dom.value).equals("1")
|
||||||
|
o(spies.valueSetter.callCount).equals(1)
|
||||||
|
|
||||||
|
render(root, [e])
|
||||||
|
|
||||||
|
o(d.dom.value).equals("2")
|
||||||
|
o(spies.valueSetter.callCount).equals(2)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
o.spec("link href", function() {
|
o.spec("link href", function() {
|
||||||
o("when link href is true, attribute is present", function() {
|
o("when link href is true, attribute is present", function() {
|
||||||
|
|
|
||||||
|
|
@ -345,18 +345,22 @@ module.exports = function(options) {
|
||||||
if (element.nodeName === "TEXTAREA") {
|
if (element.nodeName === "TEXTAREA") {
|
||||||
var wasNeverSet = true
|
var wasNeverSet = true
|
||||||
var value = ""
|
var value = ""
|
||||||
|
var valueSetter = spy(function(v) {
|
||||||
|
wasNeverSet = false
|
||||||
|
/*eslint-disable no-implicit-coercion*/
|
||||||
|
value = v === null ? "" : "" + v
|
||||||
|
/*eslint-enable no-implicit-coercion*/
|
||||||
|
})
|
||||||
Object.defineProperty(element, "value", {
|
Object.defineProperty(element, "value", {
|
||||||
get: function() {
|
get: function() {
|
||||||
return wasNeverSet && this.firstChild ? this.firstChild.nodeValue : value
|
return wasNeverSet && this.firstChild ? this.firstChild.nodeValue : value
|
||||||
},
|
},
|
||||||
set: function(v) {
|
set: valueSetter,
|
||||||
wasNeverSet = false
|
|
||||||
/*eslint-disable no-implicit-coercion*/
|
|
||||||
value = v === null ? "" : "" + v
|
|
||||||
/*eslint-enable no-implicit-coercion*/
|
|
||||||
},
|
|
||||||
enumerable: true,
|
enumerable: true,
|
||||||
})
|
})
|
||||||
|
registerSpies(element, {
|
||||||
|
valueSetter: valueSetter
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/* eslint-disable radix */
|
/* eslint-disable radix */
|
||||||
|
|
|
||||||
|
|
@ -1237,5 +1237,21 @@ o.spec("domMock", function() {
|
||||||
o(spies.valueSetter.this).equals(option)
|
o(spies.valueSetter.this).equals(option)
|
||||||
o(spies.valueSetter.args[0]).equals("aaa")
|
o(spies.valueSetter.args[0]).equals("aaa")
|
||||||
})
|
})
|
||||||
|
o("textarea elements have spies on value setters", function() {
|
||||||
|
var textarea = $window.document.createElement("textarea")
|
||||||
|
|
||||||
|
var spies = $window.__getSpies(textarea)
|
||||||
|
|
||||||
|
o(typeof spies).equals("object")
|
||||||
|
o(spies).notEquals(null)
|
||||||
|
o(typeof spies.valueSetter).equals("function")
|
||||||
|
o(spies.valueSetter.callCount).equals(0)
|
||||||
|
|
||||||
|
textarea.value = "aaa"
|
||||||
|
|
||||||
|
o(spies.valueSetter.callCount).equals(1)
|
||||||
|
o(spies.valueSetter.this).equals(textarea)
|
||||||
|
o(spies.valueSetter.args[0]).equals("aaa")
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue