-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Expand file tree
/
Copy pathscroll-padding-focus.html
More file actions
66 lines (62 loc) · 1.69 KB
/
scroll-padding-focus.html
File metadata and controls
66 lines (62 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<!DOCTYPE html>
<link rel="help" href="https://drafts.csswg.org/css-scroll-snap-1/#scroll-padding">
<title>Scroll into view for focus respects scroll padding</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
#scroller {
height: 200px;
width: 600px;
margin: 50px;
scroll-padding: 0 120px;
scrollbar-width: none;
overflow: auto;
border: 1px solid black;
}
.wide {
width: 2000px;
}
#target {
width: 100px;
height: 100px;
margin: 10px;
margin-left: 600px;
background-color: silver;
}
</style>
<div id="scroller">
<div class="wide">
<div id="target" tabindex="-1" style="background-color: green"></div>
</div>
</div>
<div id="other-focus" tabindex="-1">Other focus</div>
<script>
function tick() {
return new Promise(resolve => {
requestAnimationFrame(() => requestAnimationFrame(resolve));
});
}
function reset()
{
document.getElementById('other-focus').focus();
}
let scroller = document.getElementById("scroller");
promise_test(async t => {
reset();
scroller.scrollTo(100, 0);
await tick();
const target = document.getElementById("target");
target.focus();
await tick(); // Work around WebKit bug.
assert_equals(scroller.scrollLeft, 350, "Focus should scroll the target from out under the left scrollpadding");
}, 'Avoid left scroll-padding');
promise_test(async t => {
reset();
scroller.scrollTo(600, 0);
await tick();
const target = document.getElementById("target");
target.focus();
await tick(); // Work around WebKit bug.
assert_equals(scroller.scrollLeft, 350, "Focus should scroll the target from out under the right scrollpadding");
}, 'Avoid right scroll-padding');
</script>