slot-fallback-content-003.html (1450B)
1 <!DOCTYPE html> 2 <meta charset="utf-8" > 3 <meta name="author" title="Di Zhang" href="mailto:dizhangg@chromium.org"> 4 <meta name="assert" content="Modify slot fallback contents, when dynamically created."> 5 <title>Shadow DOM: Slots and fallback contents</title> 6 <link rel="match" href="slot-fallback-content-003-ref.html"> 7 8 <p>Test passes if there are two lines of text "SLOT1", "A" below.</p> 9 10 <div id="host1"><slot id="slot1">SLOT1</slot></div> 11 12 <p>Test passes if there is one line of text "C" below.</p> 13 14 <div id="host2"><slot id="slot2"> 15 <div id="B">FAIL</div> 16 <div id="C">C</div> 17 </slot></div> 18 19 <p>Test passes if empty.</p> 20 21 <div id="host3"> 22 <slot id="slot3"> 23 <div id="D">FAIL</div> 24 </slot> 25 </div> 26 27 <script> 28 // Content added to existing fallback content will be rendered 29 const shadowRoot1 = host1.attachShadow({ mode: "open" }); 30 shadowRoot1.appendChild(slot1); 31 const A = document.createElement('div'); 32 A.innerText = 'A'; 33 shadowRoot1.getElementById('slot1').appendChild(A); 34 35 // Remove some content from existing slot fallback will render the leftover fallback 36 const shadowRoot2 = host2.attachShadow({ mode: "open" }); 37 shadowRoot2.appendChild(slot2); 38 const B = shadowRoot2.getElementById('B'); 39 B.remove(); 40 41 // // Remove all content from existing slot fallback will render no fallback 42 const shadowRoot3 = host3.attachShadow({ mode: "open" }); 43 shadowRoot3.appendChild(slot3); 44 const D = shadowRoot3.getElementById('D'); 45 D.remove(); 46 47 </script>