Skip to content

Commit 1147808

Browse files
karlseguinmookums
authored andcommitted
Start working on HTMLSlotElement
1 parent 0b67459 commit 1147808

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<script src="../testing.js"></script>
2+
<script>
3+
class LightPanda extends HTMLElement {
4+
constructor() {
5+
super();
6+
}
7+
8+
connectedCallback() {
9+
const shadow = this.attachShadow({ mode: "open" });
10+
11+
const slot1 = document.createElement('slot');
12+
slot1.name = 'slot-1';
13+
shadow.appendChild(slot1);
14+
15+
switch (this.getAttribute('mode')) {
16+
case '1':
17+
slot1.innerHTML = 'hello';
18+
break;
19+
case '2':
20+
const slot2 = document.createElement('slot');
21+
shadow.appendChild(slot2);
22+
break;
23+
}
24+
}
25+
}
26+
window.customElements.define("lp-test", LightPanda);
27+
</script>
28+
29+
<lp-test id=lp1 mode=1></lp-test>
30+
<lp-test id=lp2 mode=0></lp-test>
31+
<lp-test id=lp3 mode=0>default</lp-test>
32+
<lp-test id=lp4 mode=1><p slot=other>default</p></lp-test>
33+
<lp-test id=lp5 mode=1><p slot=slot-1>default</p> xx <b slot=slot-1>other</b></lp-test>
34+
<lp-test id=lp6 mode=2>More <p slot=slot-1>default2</p> <span>!!</span></lp-test>
35+
36+
<script id=HTMLSlotElement>
37+
function assertNodes(expected, actual) {
38+
actual = actual.map((n) => n.id || n.textContent)
39+
testing.expectEqual(expected, actual);
40+
}
41+
42+
for (let idx of [1, 2, 3, 4]) {
43+
const lp = $(`#lp${idx}`);
44+
const slot = lp.shadowRoot.querySelector('slot');
45+
46+
assertNodes([], slot.assignedNodes());
47+
assertNodes([], slot.assignedNodes({}));
48+
assertNodes([], slot.assignedNodes({flatten: false}));
49+
if (lp.getAttribute('mode') === '1') {
50+
assertNodes(['hello'], slot.assignedNodes({flatten: true}));
51+
} else {
52+
assertNodes([], slot.assignedNodes({flatten: true}));
53+
}
54+
}
55+
56+
const lp5 = $('#lp5');
57+
const s5 = lp5.shadowRoot.querySelector('slot');
58+
assertNodes(['default', 'other'], s5.assignedNodes());
59+
60+
const lp6 = $('#lp6');
61+
const s6 = lp6.shadowRoot.querySelectorAll('slot');
62+
assertNodes(['default2'], s6[0].assignedNodes({}));
63+
assertNodes(['default2'], s6[0].assignedNodes({flatten: true}));
64+
assertNodes(['More ', ' ', '!!'], s6[1].assignedNodes({}));
65+
assertNodes(['More ', ' ', '!!'], s6[1].assignedNodes({flatten: true}));
66+
</script>

0 commit comments

Comments
 (0)