diff --git a/render/render.js b/render/render.js index de1766b3..d0346fd2 100644 --- a/render/render.js +++ b/render/render.js @@ -480,12 +480,23 @@ module.exports = function($window) { else if (key[0] === "o" && key[1] === "n" && typeof value === "function") updateEvent(vnode, key, value) else if (key === "style") updateStyle(element, old, value) else if (key in element && !isAttribute(key) && ns === undefined && !isCustomElement(vnode)) { - //setting input[value] to same value by typing on focused element moves cursor to end in Chrome - if (vnode.tag === "input" && key === "value" && vnode.dom.value == value && vnode.dom === $doc.activeElement) return - //setting select[value] to same value while having select open blinks select dropdown in Chrome - if (vnode.tag === "select" && key === "value" && vnode.dom.value == value && vnode.dom === $doc.activeElement) return - //setting option[value] to same value while having select open blinks select dropdown in Chrome - if (vnode.tag === "option" && key === "value" && old != null && vnode.dom.value == value) return + if (key === "value") { + /*eslint-disable no-implicit-coercion*/ + var normalized = "" + value + /*eslint-enable no-implicit-coercion*/ + //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 + //setting select[value] to same value while having select open blinks select dropdown in Chrome + if (vnode.tag === "select") { + if (value === null) { + if (vnode.dom.selectedIndex === -1 && vnode.dom === $doc.activeElement) return + } else { + if (old !== null && vnode.dom.value === normalized && vnode.dom === $doc.activeElement) return + } + } + //setting option[value] to same value while having select open blinks select dropdown in Chrome + if (vnode.tag === "option" && old != null && vnode.dom.value === normalized) return + } // If you assign an input type that is not supported by IE 11 with an assignment expression, an error will occur. if (vnode.tag === "input" && key === "type") { element.setAttribute(key, value) diff --git a/render/tests/test-attributes.js b/render/tests/test-attributes.js index 21c090f0..64a3fdfd 100644 --- a/render/tests/test-attributes.js +++ b/render/tests/test-attributes.js @@ -203,10 +203,10 @@ o.spec("attributes", function() { o(b.dom.value).equals("") - // #1595 redux - render(root, [c]); + // #1595 redux + render(root, [c]); - o(c.dom.value).equals("0") + o(c.dom.value).equals("0") }) o("isn't set when equivalent to the previous value and focused", function() { var $window = domMock({spy: o.spy}) @@ -476,7 +476,7 @@ o.spec("attributes", function() { o(a.dom.value).equals("") - // #1595 redux + // #1595 redux render(root, [b]) o(b.dom.value).equals("0")