Source code

Revision control

Copy as Markdown

Other Tools

Test Info: Warnings

<!DOCTYPE html>
<title>CSS Test (Display): <slot> elements should be tabbable</title>
<link rel="author" title="L. David Baron" href="https://dbaron.org/">
<link rel="author" title="Google" href="http://www.google.com/">
<link rel="help" href="https://github.com/whatwg/html/pull/9425">
<!--
This requirement is not particularly clear from current specs,
so this test is tentative. See issues above.
-->
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<body>
<div id="before" tabindex="1" style="height: 10px"></div>
<script>
function do_test(slot_style, description) {
promise_test(
async () => {
let before = document.getElementById("before");
before.focus();
let host = document.createElement("div");
document.body.appendChild(host);
var root = host.attachShadow({mode:"open"});
root.innerHTML = `
<style>
slot { --test-value: slot-not-focused; }
slot:focus { --test-value: slot-is-focused; }
</style>
<slot tabindex="1" style="${slot_style}"></slot>
`;
let slot = root.querySelector("slot");
let cs = getComputedStyle(slot);
assert_equals(document.activeElement, before, "precondition");
assert_not_equals(root.activeElement, slot, "precondition");
assert_equals(cs.getPropertyValue("--test-value"), "slot-not-focused", "precondition (style)");
await test_driver.send_keys(before, "\uE004");
assert_equals(root.activeElement, slot, "slot is now focused");
assert_equals(cs.getPropertyValue("--test-value"), "slot-is-focused", "slot is now focused (style)");
document.body.removeChild(host);
}, `slot element with ${description} should be focusable`);
}
do_test("display: block", "display: block");
do_test("", "default style");
</script>