From 0f9d5f1631275fb7aa13a750b4f80610614ad49b Mon Sep 17 00:00:00 2001 From: spacejack Date: Sun, 30 Apr 2017 15:04:37 -0400 Subject: [PATCH 1/2] Fix select option to use empty string value, add tests. --- render/render.js | 2 +- render/tests/test-input.js | 41 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/render/render.js b/render/render.js index df26a1df..4800bb44 100644 --- a/render/render.js +++ b/render/render.js @@ -481,7 +481,7 @@ module.exports = function($window) { //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" && vnode.dom.value == value) return + if (vnode.tag === "option" && key === "value" && old != null && vnode.dom.value == value) 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-input.js b/render/tests/test-input.js index 57706b9c..e75da0ef 100644 --- a/render/tests/test-input.js +++ b/render/tests/test-input.js @@ -90,6 +90,47 @@ o.spec("form inputs", function() { o(select.dom.firstChild.value).equals("") }) + o("option value defaults to textContent unless explicitly set", function() { + var select = {tag: "select", children :[ + {tag: "option", text: "aaa"} + ]} + + render(root, [select]) + + o(select.dom.firstChild.value).equals("aaa") + o(select.dom.value).equals("aaa") + + //test that value changes when content changes + select = {tag: "select", children :[ + {tag: "option", text: "bbb"} + ]} + + render(root, [select]) + + o(select.dom.firstChild.value).equals("bbb") + o(select.dom.value).equals("bbb") + + //test that value can be set to "" in subsequent render + select = {tag: "select", children :[ + {tag: "option", attrs: {value: ""}, text: "aaa"} + ]} + + render(root, [select]) + + o(select.dom.firstChild.value).equals("") + o(select.dom.value).equals("") + + //test that value reverts to textContent when value omitted + select = {tag: "select", children :[ + {tag: "option", text: "ccc"} + ]} + + render(root, [select]) + + o(select.dom.firstChild.value).equals("ccc") + o(select.dom.value).equals("ccc") + }) + o("select yields invalid value without children", function() { var select = {tag: "select", attrs: {value: "a"}} From 08a6638926bab905277c2d60c4dd68e9beb91724 Mon Sep 17 00:00:00 2001 From: spacejack Date: Sun, 30 Apr 2017 15:14:44 -0400 Subject: [PATCH 2/2] Minimize vdom diff in option value test --- render/tests/test-input.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/render/tests/test-input.js b/render/tests/test-input.js index e75da0ef..d61bad54 100644 --- a/render/tests/test-input.js +++ b/render/tests/test-input.js @@ -122,13 +122,13 @@ o.spec("form inputs", function() { //test that value reverts to textContent when value omitted select = {tag: "select", children :[ - {tag: "option", text: "ccc"} + {tag: "option", text: "aaa"} ]} render(root, [select]) - o(select.dom.firstChild.value).equals("ccc") - o(select.dom.value).equals("ccc") + o(select.dom.firstChild.value).equals("aaa") + o(select.dom.value).equals("aaa") }) o("select yields invalid value without children", function() {