diff --git a/src/lib/dom-api-shadow.html b/src/lib/dom-api-shadow.html
index 3cdb7ea8fd..daf15df8d9 100644
--- a/src/lib/dom-api-shadow.html
+++ b/src/lib/dom-api-shadow.html
@@ -60,11 +60,13 @@
activeElement: {
get: function() {
- return Polymer.DomApi.wrap(this.node).activeElement;
+ var node = Polymer.DomApi.wrap(this.node);
+ var activeElement = node.activeElement;
+ return node.contains(activeElement) ? activeElement : null;
},
configurable: true
},
-
+
childNodes: {
get: function() {
return TreeApi.arrayCopyChildNodes(this.node);
diff --git a/src/lib/dom-api-shady.html b/src/lib/dom-api-shady.html
index 9d00661e95..ccb9335429 100644
--- a/src/lib/dom-api-shady.html
+++ b/src/lib/dom-api-shady.html
@@ -430,35 +430,35 @@
}
var isShadyRoot = !!this.node._isShadyRoot;
if (this.node !== document) {
- // If this node isn't a document or shady root, then it doesn't
- // have an active element.
+ // If this node isn't a document or shady root, then it doesn't have
+ // an active element.
if (!isShadyRoot) {
return null;
}
// If this shady root's host is the active element or the active
- // element is not a descendant of the host, then it doesn't have
- // an active element.
+ // element is not a descendant of the host (in the composed tree),
+ // then it doesn't have an active element.
if (this.node.host === active ||
!this.node.host.contains(active)) {
return null;
}
- // If the active element is a light descendant of the shady root's
- // host, return the active element.
- if (this.node.host !== active &&
- this._contains(this.node.host, active)) {
- return active;
- }
}
- // This node is either the document or a shady root of which the
- // active element is a descendant of its host; iterate upwards to
- // find the active element's most shallow host.
+ // This node is either the document or a shady root of which the active
+ // element is a (composed) descendant of its host; iterate upwards to
+ // find the active element's most shallow host within it.
var activeRoot = Polymer.dom(active).getOwnerRoot();
- while (activeRoot && activeRoot !== this.node &&
- !(isShadyRoot && this._contains(this.node.host, active))) {
+ while (activeRoot && activeRoot !== this.node) {
active = activeRoot.host;
activeRoot = Polymer.dom(active).getOwnerRoot();
}
- return active;
+ if (this.node === document) {
+ // This node is the document, so activeRoot should be null.
+ return activeRoot ? null : active;
+ } else {
+ // This node is a non-document shady root, and it should be
+ // activeRoot.
+ return activeRoot === this.node ? active : null;
+ }
},
configurable: true
},
diff --git a/test/unit/polymer-dom.js b/test/unit/polymer-dom.js
index f6e06747ea..ab9f735d7f 100644
--- a/test/unit/polymer-dom.js
+++ b/test/unit/polymer-dom.js
@@ -868,7 +868,7 @@ suite('Polymer.dom accessors', function() {
r_l.focus();
assert.equal(Polymer.dom(document).activeElement, r_l, 'document.activeElement === r_l');
- assert.equal(Polymer.dom(r.root).activeElement, r_l, 'r.root.activeElement === r_l');
+ assert.equal(Polymer.dom(r.root).activeElement, null, 'r.root.activeElement === null');
assert.equal(Polymer.dom(r_0.root).activeElement, null, 'r_0.root.activeElement === null');
assert.equal(Polymer.dom(r_0_0.root).activeElement, null, 'r_0_0.root.activeElement === null');
assert.equal(Polymer.dom(r_0_1.root).activeElement, null, 'r_0_1.root.activeElement === null');
@@ -895,7 +895,7 @@ suite('Polymer.dom accessors', function() {
assert.equal(Polymer.dom(document).activeElement, r, 'document.activeElement === r');
assert.equal(Polymer.dom(r.root).activeElement, r_0_l, 'r.root.activeElement === r_0_l');
- assert.equal(Polymer.dom(r_0.root).activeElement, r_0_l, 'r_0.root.activeElement === r_0_l');
+ assert.equal(Polymer.dom(r_0.root).activeElement, null, 'r_0.root.activeElement === null');
assert.equal(Polymer.dom(r_1.root).activeElement, null, 'r_1.root.activeElement === null');
assert.equal(Polymer.dom(r_0_0.root).activeElement, null, 'r_0_0.root.activeElement === null');
@@ -923,7 +923,7 @@ suite('Polymer.dom accessors', function() {
assert.equal(Polymer.dom(document).activeElement, r, 'document.activeElement === r');
assert.equal(Polymer.dom(r.root).activeElement, r_0, 'r.root.activeElement === r_0');
assert.equal(Polymer.dom(r_0.root).activeElement, r_0_0_l, 'r_0.root.activeElement === r_0_0_l');
- assert.equal(Polymer.dom(r_0_0.root).activeElement, r_0_0_l, 'r_0_0.root.activeElement === r_0_0_l');
+ assert.equal(Polymer.dom(r_0_0.root).activeElement, null, 'r_0_0.root.activeElement === null');
assert.equal(Polymer.dom(r_0_1.root).activeElement, null, 'r_0_1.root.activeElement === null');
assert.equal(Polymer.dom(r_1.root).activeElement, null, 'r_1.root.activeElement === null');
assert.equal(Polymer.dom(r_1_0.root).activeElement, null, 'r_1_0.root.activeElement === null');
@@ -936,7 +936,7 @@ suite('Polymer.dom accessors', function() {
assert.equal(Polymer.dom(document).activeElement, r, 'document.activeElement === r');
assert.equal(Polymer.dom(r.root).activeElement, r_0, 'r.root.activeElement === r_0');
assert.equal(Polymer.dom(r_0.root).activeElement, r_0_0_l, 'r_0.root.activeElement === r_0_0_l');
- assert.equal(Polymer.dom(r_0_0.root).activeElement, r_0_0_l, 'r_0_0.root.activeElement === r_0_0_l');
+ assert.equal(Polymer.dom(r_0_0.root).activeElement, null, 'r_0_0.root.activeElement === null');
assert.equal(Polymer.dom(r_0_0_l.root).activeElement, r_0_0_l_0, 'r_0_0_l.root.activeElement === r_0_0_l_0');
assert.equal(Polymer.dom(r_0_1.root).activeElement, null, 'r_0_1.root.activeElement === null');
assert.equal(Polymer.dom(r_1.root).activeElement, null, 'r_1.root.activeElement === null');
@@ -964,7 +964,7 @@ suite('Polymer.dom accessors', function() {
assert.equal(Polymer.dom(r.root).activeElement, r_0, 'r.root.activeElement === r_0');
assert.equal(Polymer.dom(r_0.root).activeElement, r_0_1_l, 'r_0.root.activeElement === r_0_1_l');
assert.equal(Polymer.dom(r_0_0.root).activeElement, null, 'r_0_0.root.activeElement === null');
- assert.equal(Polymer.dom(r_0_1.root).activeElement, r_0_1_l, 'r_0_1.root.activeElement === r_0_1_l');
+ assert.equal(Polymer.dom(r_0_1.root).activeElement, null, 'r_0_1.root.activeElement === null');
assert.equal(Polymer.dom(r_1.root).activeElement, null, 'r_1.root.activeElement === null');
assert.equal(Polymer.dom(r_1_0.root).activeElement, null, 'r_1_0.root.activeElement === null');
assert.equal(Polymer.dom(r_1_1.root).activeElement, null, 'r_1_1.root.activeElement === null');
@@ -991,7 +991,7 @@ suite('Polymer.dom accessors', function() {
assert.equal(Polymer.dom(r_0.root).activeElement, null, 'r_0.root.activeElement === null');
assert.equal(Polymer.dom(r_0_0.root).activeElement, null, 'r_0_0.root.activeElement === null');
assert.equal(Polymer.dom(r_0_1.root).activeElement, null, 'r_0_1.root.activeElement === null');
- assert.equal(Polymer.dom(r_1.root).activeElement, r_1_l, 'r_1.root.activeElement === r_1_l');
+ assert.equal(Polymer.dom(r_1.root).activeElement, null, 'r_1.root.activeElement === null');
assert.equal(Polymer.dom(r_1_0.root).activeElement, null, 'r_1_0.root.activeElement === null');
assert.equal(Polymer.dom(r_1_1.root).activeElement, null, 'r_1_1.root.activeElement === null');
});
@@ -1004,7 +1004,7 @@ suite('Polymer.dom accessors', function() {
assert.equal(Polymer.dom(r_0.root).activeElement, null, 'r_0.root.activeElement === null');
assert.equal(Polymer.dom(r_0_0.root).activeElement, null, 'r_0_0.root.activeElement === null');
assert.equal(Polymer.dom(r_0_1.root).activeElement, null, 'r_0_1.root.activeElement === null');
- assert.equal(Polymer.dom(r_1.root).activeElement, r_1_l, 'r_1.root.activeElement === r_1_l');
+ assert.equal(Polymer.dom(r_1.root).activeElement, null, 'r_1.root.activeElement === null');
assert.equal(Polymer.dom(r_1_l.root).activeElement, r_1_l_0, 'r_1.root.activeElement === r_1_l_0');
assert.equal(Polymer.dom(r_1_0.root).activeElement, null, 'r_1_0.root.activeElement === null');
assert.equal(Polymer.dom(r_1_1.root).activeElement, null, 'r_1_1.root.activeElement === null');
@@ -1032,7 +1032,7 @@ suite('Polymer.dom accessors', function() {
assert.equal(Polymer.dom(r_0_0.root).activeElement, null, 'r_0_0.root.activeElement === null');
assert.equal(Polymer.dom(r_0_1.root).activeElement, null, 'r_0_1.root.activeElement === null');
assert.equal(Polymer.dom(r_1.root).activeElement, r_1_0_l, 'r_1.root.activeElement === r_1_0_l');
- assert.equal(Polymer.dom(r_1_0.root).activeElement, r_1_0_l, 'r_1_0.root.activeElement === r_1_0_l');
+ assert.equal(Polymer.dom(r_1_0.root).activeElement, null, 'r_1_0.root.activeElement === null');
assert.equal(Polymer.dom(r_1_1.root).activeElement, null, 'r_1_1.root.activeElement === null');
});
@@ -1059,7 +1059,7 @@ suite('Polymer.dom accessors', function() {
assert.equal(Polymer.dom(r_0_1.root).activeElement, null, 'r_0_1.root.activeElement === null');
assert.equal(Polymer.dom(r_1.root).activeElement, r_1_1_l, 'r_1.root.activeElement === r_1_1_l');
assert.equal(Polymer.dom(r_1_0.root).activeElement, null, 'r_1_0.root.activeElement === null');
- assert.equal(Polymer.dom(r_1_1.root).activeElement, r_1_1_l, 'r_1_1.root.activeElement === r_1_1_l');
+ assert.equal(Polymer.dom(r_1_1.root).activeElement, null, 'r_1_1.root.activeElement === null');
});
test('setting activeElement on document has no effect', function() {