Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test has a WPT meta file that expects 2 subtest issues.
- This WPT test may be referenced by the following Test IDs:
- /html/semantics/forms/the-selectlist-element/tab-closes-listbox.tentative.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<link rel=author href="mailto:jarhar@chromium.org">
<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>
<selectlist id=defaultlistbox>
<option>one</option>
<option>two</option>
</selectlist>
<selectlist id=customlistbox>
<listbox>
<option>one</option>
<option>two</option>
</listbox>
</selectlist>
<script>
const tabKey = '\uE004';
document.querySelectorAll('selectlist').forEach(selectlist => {
promise_test(async () => {
selectlist.focus();
await test_driver.send_keys(selectlist, ' ');
assert_true(selectlist.open, 'Listbox should be open after pressing space.');
selectlist.addEventListener('keydown', event => {
if (event.key === 'Tab') {
event.preventDefault();
}
}, {once: true});
await test_driver.send_keys(document.activeElement, tabKey);
assert_true(selectlist.open, 'Listbox should stay open when the tab keydown is preventDefaulted.');
await test_driver.send_keys(document.activeElement, tabKey);
assert_false(selectlist.open, 'Listbox should close after pressing the tab key.');
}, `${selectlist.id}: Pressing tab should close the listbox.`);
});
</script>