fix: Allow for changing focus in lifecycle hooks (#1988)
This commit is contained in:
parent
bfdbf1a0aa
commit
4aac74eff3
3 changed files with 37 additions and 9 deletions
|
|
@ -621,9 +621,9 @@ module.exports = function($window) {
|
|||
if (!Array.isArray(vnodes)) vnodes = [vnodes]
|
||||
updateNodes(dom, dom.vnodes, Vnode.normalizeChildren(vnodes), false, hooks, null, namespace === "http://www.w3.org/1999/xhtml" ? undefined : namespace)
|
||||
dom.vnodes = vnodes
|
||||
for (var i = 0; i < hooks.length; i++) hooks[i]()
|
||||
// document.activeElement can return null in IE https://developer.mozilla.org/en-US/docs/Web/API/Document/activeElement
|
||||
if (active != null && $doc.activeElement !== active) active.focus()
|
||||
for (var i = 0; i < hooks.length; i++) hooks[i]()
|
||||
}
|
||||
|
||||
return {render: render, setEventCallback: setEventCallback}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,16 @@ o.spec("form inputs", function() {
|
|||
o($window.document.activeElement).equals(input.dom)
|
||||
})
|
||||
|
||||
o("maintains focus when changed manually in hook", function() {
|
||||
var input = {tag: "input", attrs: {oncreate: function() {
|
||||
input.dom.focus();
|
||||
}}};
|
||||
|
||||
render(root, [input])
|
||||
|
||||
o($window.document.activeElement).equals(input.dom)
|
||||
})
|
||||
|
||||
o("syncs input value if DOM value differs from vdom value", function() {
|
||||
var input = {tag: "input", attrs: {value: "aaa", oninput: function() {}}}
|
||||
var updated = {tag: "input", attrs: {value: "aaa", oninput: function() {}}}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue