invalidation-part-pseudo.html (1793B)
1 <!doctype html> 2 <title>CSS Shadow Parts - Pseudo class and exported parts</title> 3 <link rel="help" href="https://drafts.csswg.org/css-shadow-parts" > 4 <link rel="help" href="https://drafts.csswg.org/selectors/#matches"> 5 <link href="https://drafts.csswg.org/selectors/#matches" rel="help"> 6 <script src="/resources/testharness.js"></script> 7 <script src="/resources/testharnessreport.js"></script> 8 <script src="/resources/testdriver.js"></script> 9 <script src="/resources/testdriver-actions.js"></script> 10 <script src="/resources/testdriver-vendor.js"></script> 11 <style> 12 /* NOTE: Even though it might be tempting to use :focus instead, because we 13 can more easily add that state programmatically, that'd defeat the point 14 of the test, since :focus / :focus-visible has default styles which 15 invalidate the element's style anyways */ 16 #host::part(a):hover { 17 background: blue; 18 } 19 </style> 20 <div id="host"></div> 21 <script> 22 let host = document.querySelector('#host') 23 host.attachShadow({mode: 'open'}).innerHTML = `<div part="b" exportparts="a"></div>`; 24 25 let innerHost = host.shadowRoot.querySelector('div'); 26 innerHost.attachShadow({mode: 'open'}).innerHTML = ` 27 <style> 28 div { 29 width: 100px; 30 height: 100px; 31 background: black; 32 color: white; 33 } 34 </style> 35 <div part="a">hover, the background should be blue</div> 36 `; 37 38 let part = innerHost.shadowRoot.querySelector("div"); 39 let t = async_test("Invalidation of nested part on hover"); 40 part.addEventListener("mouseover", t.step_func_done(function() { 41 assert_true(part.matches(":hover"), "Element should be hovered"); 42 assert_equals(getComputedStyle(part).backgroundColor, "rgb(0, 0, 255)", "Hover style should apply"); 43 })); 44 45 new test_driver.Actions() 46 .pointerMove(0, 0) 47 .pointerMove(50, 50) 48 .send(); 49 </script>