Fix #1771 and probably others (#2286)

This is *super* subtle, and IMHO Chrome did exactly the wrong thing
here.
This commit is contained in:
Isiah Meadows 2018-11-14 15:35:00 -05:00 committed by GitHub
parent 76e585c523
commit 4f68984f2f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 40 additions and 0 deletions

View file

@ -87,6 +87,13 @@ module.exports = function(options) {
var index = this.childNodes.indexOf(child)
if (index > -1) {
this.childNodes.splice(index, 1)
// Yes, *this* is the behavior Chrome has and what FF is considering in
// https://bugzilla.mozilla.org/show_bug.cgi?id=559561
if (activeElement === child) {
var blur = $window.document.createEvent()
blur.initEvent("blur")
child.dispatchEvent(blur)
}
child.parentNode = null
}
else throw new TypeError("Failed to execute 'removeChild'")

View file

@ -208,6 +208,19 @@ o.spec("domMock", function() {
try {parent.removeChild(child)}
catch (e) {done()}
})
o("invokes blur on child if focused", function() {
var parent = $document.createElement("div")
var child = $document.createElement("a")
var spy = o.spy()
parent.appendChild(child)
child.addEventListener("blur", spy, false)
child.focus()
parent.removeChild(child)
o(spy.callCount).equals(1)
o(spy.args[0].type).equals("blur")
o(spy.args[0].target).equals(child)
})
})
o.spec("insertBefore", function() {