From d21bfd4a36e940430052c6f860a0298bccd2b597 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Gerardy Date: Mon, 29 May 2017 16:47:14 +0200 Subject: [PATCH 1/3] Enable the tests for the updated #1595, add an additional sanity check --- render/tests/test-attributes.js | 48 +++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/render/tests/test-attributes.js b/render/tests/test-attributes.js index c469fcdb..21c090f0 100644 --- a/render/tests/test-attributes.js +++ b/render/tests/test-attributes.js @@ -193,6 +193,7 @@ o.spec("attributes", function() { o("'' and 0 are different values", function() { var a = {tag: "input", attrs: {value: 0}, children:[{tag:"#", children:""}]} var b = {tag: "input", attrs: {value: ""}, children:[{tag:"#", children:""}]} + var c = {tag: "input", attrs: {value: 0}, children:[{tag:"#", children:""}]} render(root, [a]); @@ -200,13 +201,12 @@ o.spec("attributes", function() { render(root, [b]); - o(a.dom.value).equals("") + o(b.dom.value).equals("") - // #1959 redux - // TODO: UNCOMMENT - // render(root, [a]); + // #1595 redux + render(root, [c]); - // o(a.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}) @@ -362,6 +362,7 @@ o.spec("attributes", function() { o("'' and 0 are different values", function() { var a = {tag: "option", attrs: {value: 0}, children:[{tag:"#", children:""}]} var b = {tag: "option", attrs: {value: ""}, children:[{tag:"#", children:""}]} + var c = {tag: "option", attrs: {value: 0}, children:[{tag:"#", children:""}]} render(root, [a]); @@ -371,11 +372,10 @@ o.spec("attributes", function() { o(a.dom.value).equals("") - // #1959 redux - // TODO: UNCOMMENT - // render(root, [a]); + // #1595 redux + render(root, [c]); - // o(a.dom.value).equals("0") + o(c.dom.value).equals("0") }) o("isn't set when equivalent to the previous value", function() { var $window = domMock({spy: o.spy}) @@ -469,18 +469,38 @@ o.spec("attributes", function() { }) o("'' and 0 are different values when focused", function() { var a = makeSelect("") - // var b = makeSelect(0) + var b = makeSelect(0) render(root, [a]) a.dom.focus() o(a.dom.value).equals("") - // #1959 redux - // TODO: UNCOMMENT - // render(root, [b]) + // #1595 redux + render(root, [b]) - // o(b.dom.value).equals("0") + o(b.dom.value).equals("0") + }) + o("'' and null are different values when focused", function() { + var a = makeSelect("") + var b = makeSelect(null) + var c = makeSelect("") + + render(root, [a]) + a.dom.focus() + + o(a.dom.value).equals("") + o(a.dom.selectedIndex).equals(4) + + render(root, [b]) + + o(b.dom.value).equals("") + o(b.dom.selectedIndex).equals(-1) + + render(root, [c]) + + o(c.dom.value).equals("") + o(c.dom.selectedIndex).equals(4) }) o("updates with the same value do not re-set the attribute if the select has focus", function() { var $window = domMock({spy: o.spy}) From 4616160a5243a99524b817383fa9c10e281da90a Mon Sep 17 00:00:00 2001 From: Pierre-Yves Gerardy Date: Mon, 29 May 2017 17:19:55 +0200 Subject: [PATCH 2/3] redo #1595 --- render/render.js | 23 +++++++++++++++++------ render/tests/test-attributes.js | 8 ++++---- 2 files changed, 21 insertions(+), 10 deletions(-) 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") From 66aa377548555694ce8edb43a2dcb16b3b0e8286 Mon Sep 17 00:00:00 2001 From: Isiah Meadows Date: Wed, 31 May 2017 02:44:15 -0400 Subject: [PATCH 3/3] Simplify ESLint guard --- render/render.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/render/render.js b/render/render.js index d0346fd2..570591c0 100644 --- a/render/render.js +++ b/render/render.js @@ -481,9 +481,7 @@ module.exports = function($window) { else if (key === "style") updateStyle(element, old, value) else if (key in element && !isAttribute(key) && ns === undefined && !isCustomElement(vnode)) { if (key === "value") { - /*eslint-disable no-implicit-coercion*/ - var normalized = "" + value - /*eslint-enable 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 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