slot-element-focusable.tentative.html (1997B)
1 <!DOCTYPE html> 2 <title>CSS Test (Display): <slot> elements should be focusable</title> 3 <link rel="author" title="L. David Baron" href="https://dbaron.org/"> 4 <link rel="author" title="Google" href="http://www.google.com/"> 5 <link rel="help" href="https://html.spec.whatwg.org/multipage/rendering.html#flow-content-3"> 6 <link rel="help" href="https://github.com/w3c/csswg-drafts/issues/2632"> 7 <link rel="help" href="https://github.com/whatwg/html/issues/1837"> 8 <link rel="help" href="https://github.com/whatwg/html/pull/9425"> 9 <link rel="help" href="https://bugs.chromium.org/p/chromium/issues/detail?id=1366037"> 10 <!-- 11 12 This requirement is not particularly clear from current specs, 13 so this test is tentative. See issues above. 14 15 --> 16 <script src="/resources/testharness.js"></script> 17 <script src="/resources/testharnessreport.js"></script> 18 19 <body> 20 21 <script> 22 23 function do_test(slot_style, description) { 24 test( 25 function() { 26 let host = document.createElement("div"); 27 document.body.appendChild(host); 28 var root = host.attachShadow({mode:"open"}); 29 root.innerHTML = ` 30 <style> 31 slot { --test-value: slot-not-focused; } 32 slot:focus { --test-value: slot-is-focused; } 33 </style> 34 <slot tabindex="1" style="${slot_style}"></slot> 35 `; 36 let slot = root.querySelector("slot"); 37 let cs = getComputedStyle(slot); 38 assert_not_equals(root.activeElement, slot, "precondition"); 39 assert_equals(cs.getPropertyValue("--test-value"), "slot-not-focused", "precondition (style)"); 40 slot.focus(); 41 assert_equals(root.activeElement, slot, "slot is now focused"); 42 assert_equals(cs.getPropertyValue("--test-value"), "slot-is-focused", "slot is now focused (style)"); 43 document.body.removeChild(host); 44 }, `slot element with ${description} should be focusable`); 45 } 46 47 do_test("display: block", "display: block"); 48 do_test("", "default style"); 49 50 </script>