Skip to content

Commit 8e6f55a

Browse files
committed
Find non distributed children with deepContains
Walk logical tree when necessary
1 parent 279bf63 commit 8e6f55a

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

src/lib/dom-api.html

+6-2
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,15 @@
6363
if (this.node.contains(node)) {
6464
return true;
6565
}
66+
6667
var n = node;
68+
// wrap document for SD polyfill
69+
var wrappedDocument = wrap(document);
6770

6871
// walk from node to `this` or `document`
69-
while (n && n !== document && n !== this.node) {
70-
n = n.parentNode || n.host;
72+
while (n && n !== wrappedDocument && n !== this.node) {
73+
// use logical parentnode, or native ShadowRoot host
74+
n = Polymer.dom(n).parentNode || n.host;
7175
}
7276
return n === this.node;
7377
},

test/unit/polymer-dom-elements.html

+4-1
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@
333333
<dom-module id="x-deep-contains">
334334
<template>
335335
<div id="shadowed"></div>
336-
<content></content>
336+
<content select="#light"></content>
337337
</template>
338338
<script>
339339
Polymer({
@@ -342,6 +342,9 @@
342342
var e = document.createElement('div');
343343
e.id = 'light';
344344
Polymer.dom(this).appendChild(e);
345+
e = document.createElement('div');
346+
e.id = 'notdistributed';
347+
Polymer.dom(this).appendChild(e);
345348
}
346349
});
347350
</script>

test/unit/polymer-dom.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -921,14 +921,16 @@ suite('Polymer.dom non-distributed elements', function() {
921921
test('Deep Contains', function() {
922922
var el = document.querySelector('x-deep-contains');
923923
var shadow = el.$.shadowed;
924-
var light = el.querySelector('#light');
924+
var light = Polymer.dom(el).querySelector('#light');
925+
var notdistributed = Polymer.dom(el).querySelector('#notdistributed');
925926
var disconnected = document.createElement('div');
926927
var separate = document.createElement('div');
927928
document.body.appendChild(separate);
928929

929930
assert.equal(Polymer.dom(el).deepContains(el), true, 'Element should deepContain itself');
930931
assert.equal(Polymer.dom(el).deepContains(shadow), true, 'Shadowed Child element should be found');
931932
assert.equal(Polymer.dom(el).deepContains(light), true, 'Light Child element should be found');
933+
assert.equal(Polymer.dom(el).deepContains(notdistributed), true, 'Non-distributed child element should be found');
932934
assert.equal(Polymer.dom(el).deepContains(disconnected), false, 'Disconnected element should not be found');
933935
assert.equal(Polymer.dom(el).deepContains(separate), false, 'Unassociated, attached element should not be found');
934936

0 commit comments

Comments
 (0)