Skip to content

Commit

Permalink
Merge pull request #1862 from pygy/fix-1595-redux
Browse files Browse the repository at this point in the history
Re-fix #1595
  • Loading branch information
Isiah Meadows committed May 31, 2017
2 parents e075be6 + 66aa377 commit 712be2b
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 20 deletions.
21 changes: 15 additions & 6 deletions render/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,12 +480,21 @@ 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") {
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
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)
Expand Down
48 changes: 34 additions & 14 deletions render/tests/test-attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,20 +193,20 @@ 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]);

o(a.dom.value).equals("0")

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})
Expand Down Expand Up @@ -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]);

Expand All @@ -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})
Expand Down Expand Up @@ -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})
Expand Down

0 comments on commit 712be2b

Please sign in to comment.