details-keyboard-activation.html (1687B)
1 <!doctype html> 2 <meta charset="utf-8"> 3 <title>Details activation with space bar</title> 4 <link rel="author" href="mailto:emilio@crisal.io" title="Emilio Cobos Álvarez"> 5 <link rel="author" href="https://mozilla.org" title="Mozilla"> 6 <link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1726454"> 7 <script src=/resources/testharness.js></script> 8 <script src=/resources/testharnessreport.js></script> 9 <script src="/resources/testdriver.js"></script> 10 <script src="/resources/testdriver-actions.js"></script> 11 <script src="/resources/testdriver-vendor.js"></script> 12 <style> 13 :root { 14 scroll-behavior: instant; 15 } 16 .spacer { 17 height: 200vh; 18 } 19 </style> 20 <details> 21 <summary>Activate me with the <kbd>Space</kbd> key</summary> 22 <p>Summary</p> 23 </details> 24 <div class="spacer"></div> 25 <script> 26 function tick() { 27 return new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve))); 28 } 29 30 promise_test(async t => { 31 const details = document.querySelector("details"); 32 const summary = details.querySelector("summary"); 33 34 summary.focus(); 35 assert_equals(document.activeElement, summary, "Summary should be focusable"); 36 assert_false(details.open, "Details should be closed"); 37 38 const oldScrollY = window.scrollY; 39 assert_equals(oldScrollY, 0, "Should be at top"); 40 41 window.addEventListener("scroll", t.unreached_func("Unexpected scroll event")); 42 43 await test_driver.send_keys(summary, " "); 44 45 assert_true(details.open, "Space bar on summary should open details"); 46 assert_equals(window.scrollY, oldScrollY, "Scroll position shouldn't change"); 47 48 await tick(); 49 50 assert_equals(window.scrollY, oldScrollY, "Scroll position shouldn't change"); 51 }); 52 </script>