Skip to content

Commit 5ccec49

Browse files
hiikezoemoz-wptsync-bot
authored andcommitted
Update scroll snap target ids when re-using an AsyncSmoothMSDScroll or an AsyncScroll instance.
In the case of `overflow:hidden` scroll container, async scroll operations are handled on the main-thread. And the scroll snap target ids are also maintained on the main-thread either by mAsyncSmoothMSDScroll or mAsyncScroll. But when re-using an existing mAsyncSmoothMSDScroll instance (or mAsyncScroll), the first scroll snap target ids had persisted in the instance, that resulted unexpected re-snapping. Differential Revision: https://phabricator.services.mozilla.com/D238731 bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1946375 gecko-commit: 09d2be57064f5291da8d4649ea373ce22d502c25 gecko-reviewers: dlrobertson
1 parent b9af5f9 commit 5ccec49

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<!DOCTYPE html>
2+
<link rel="help" href="https://drafts.csswg.org/css-scroll-snap/#re-snap" />
3+
<meta name="viewport" content="width=device-width,initial-scale=1">
4+
<link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1946375">
5+
<script src="/resources/testharness.js"></script>
6+
<script src="/resources/testharnessreport.js"></script>
7+
<style>
8+
#scroller {
9+
display: flex;
10+
overflow-x: hidden;
11+
scroll-snap-align: start;
12+
scroll-snap-type: x mandatory;
13+
width: 500px;
14+
height: 200px;
15+
position: absolute;
16+
}
17+
.child {
18+
display: flex;
19+
flex: 0 0 500px;
20+
scroll-snap-align: start;
21+
width: 500px;
22+
height: 100%;
23+
align-items: center;
24+
justify-content: center;
25+
font-size: 30px;
26+
}
27+
</style>
28+
<div id="scroller">
29+
<div class="child" style="background-color: blue;">1</div>
30+
<div class="child" style="background-color: green;">2</div>
31+
<div class="child" style="background-color: yellow;">3</div>
32+
</div>
33+
<script>
34+
promise_test(async () => {
35+
assert_equals(scroller.scrollLeft, 0, "The initial scroll position");
36+
37+
const scrollPromise = new Promise(resolve => {
38+
scroller.addEventListener("scroll", resolve);
39+
});
40+
// Do an async scroll operation to the second child.
41+
scroller.scrollTo({ left: 500, behavior: "smooth" });
42+
43+
// Wait a scroll event.
44+
await scrollPromise;
45+
46+
// Assuming that the current scroll position is not yet the scroll
47+
// destination, i.e. during the async scroll is runnig try to do
48+
// a new async scroll operation to the third child.
49+
const scrollendPromise = new Promise(resolve => {
50+
scroller.addEventListener("scrollend", resolve);
51+
});
52+
scroller.scrollTo({ left: 1000, behavior: "smooth" });
53+
await scrollendPromise;
54+
55+
assert_equals(scroller.scrollLeft, 1000,
56+
"Now the scroll position should be 1000px");
57+
58+
// Change a child element width so that re-snapping will happen.
59+
document.querySelectorAll(".child")[0].style.width = "501px";
60+
61+
assert_equals(scroller.scrollLeft, 1000, "The scroll position should stay");
62+
});
63+
</script>

0 commit comments

Comments
 (0)