diff --git a/src/lib/dom-api.html b/src/lib/dom-api.html index df38fc68f5..75ceea0921 100644 --- a/src/lib/dom-api.html +++ b/src/lib/dom-api.html @@ -63,11 +63,15 @@ if (this.node.contains(node)) { return true; } + var n = node; + // wrap document for SD polyfill + var wrappedDocument = wrap(document); // walk from node to `this` or `document` - while (n && n !== document && n !== this.node) { - n = n.parentNode || n.host; + while (n && n !== wrappedDocument && n !== this.node) { + // use logical parentnode, or native ShadowRoot host + n = Polymer.dom(n).parentNode || n.host; } return n === this.node; }, diff --git a/test/unit/polymer-dom-elements.html b/test/unit/polymer-dom-elements.html index 0129b71513..8065f0b727 100644 --- a/test/unit/polymer-dom-elements.html +++ b/test/unit/polymer-dom-elements.html @@ -333,7 +333,7 @@ diff --git a/test/unit/polymer-dom.js b/test/unit/polymer-dom.js index 4a61228980..d198a4580a 100644 --- a/test/unit/polymer-dom.js +++ b/test/unit/polymer-dom.js @@ -921,7 +921,8 @@ suite('Polymer.dom non-distributed elements', function() { test('Deep Contains', function() { var el = document.querySelector('x-deep-contains'); var shadow = el.$.shadowed; - var light = el.querySelector('#light'); + var light = Polymer.dom(el).querySelector('#light'); + var notdistributed = Polymer.dom(el).querySelector('#notdistributed'); var disconnected = document.createElement('div'); var separate = document.createElement('div'); document.body.appendChild(separate); @@ -929,6 +930,7 @@ suite('Polymer.dom non-distributed elements', function() { assert.equal(Polymer.dom(el).deepContains(el), true, 'Element should deepContain itself'); assert.equal(Polymer.dom(el).deepContains(shadow), true, 'Shadowed Child element should be found'); assert.equal(Polymer.dom(el).deepContains(light), true, 'Light Child element should be found'); + assert.equal(Polymer.dom(el).deepContains(notdistributed), true, 'Non-distributed child element should be found'); assert.equal(Polymer.dom(el).deepContains(disconnected), false, 'Disconnected element should not be found'); assert.equal(Polymer.dom(el).deepContains(separate), false, 'Unassociated, attached element should not be found');