Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent document from scrolling in customizable select popover #49104

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<!DOCTYPE html>
<link rel=author href="mailto:jarhar@chromium.org">
<link rel=help href="https://github.com/openui/open-ui/issues/1087#issuecomment-2381094286">
<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>

<style>
select, ::picker(select) {
appearance: base-select;
}
.spacer {
height: 10000px;
}
</style>

<select id=topofdocument>
<option>one</option>
<option>two</option>
</select>

<div class=spacer></div>

<select id=bottomofdocument>
<option>one</option>
<option>two</option>
</select>

<script>
const ArrowUp = '\uE013';
const ArrowDown = '\uE015';
['topofdocument', 'bottomofdocument'].forEach(selectName => {
const select = document.getElementById(selectName);
promise_test(async () => {
select.scrollIntoView();
await test_driver.click(select);
assert_equals(document.activeElement, select.querySelector('option'),
'First option should be focused when opening the select.');

const scroll = window.scrollY;
await test_driver.send_keys(document.activeElement, ArrowUp);
await test_driver.send_keys(document.activeElement, ArrowUp);
assert_equals(window.scrollY, scroll,
'Document should not be scrolled when pressing ArrowUp on the first option.');

await test_driver.send_keys(document.activeElement, ArrowDown);
await test_driver.send_keys(document.activeElement, ArrowDown);
assert_equals(window.scrollY, scroll,
'Document should not be scrolled when pressing ArrowDown on the last option.');
}, `${selectName}: Arrow keys on options should not scroll the document.`);
});
</script>