Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test has a WPT meta file that expects 3 subtest issues.
- This WPT test may be referenced by the following Test IDs:
- /css/css-conditional/container-queries/scroll-state/scroll-direction-hv.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<title>@container: scroll-state(direction) state is persisted across horizontal and vertical scrolling</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/css/css-conditional/container-queries/support/cq-testcommon.js"></script>
<script src="/css/css-transitions/support/helper.js"></script>
<style>
#scroller {
width: 200px;
height: 200px;
container-type: scroll-state;
overflow: scroll;
}
#filler {
height: 600px;
width: 600px;
}
#target {
--top: no;
--bottom: no;
--left: no;
--right: no;
--none: no;
@container scroll-state(direction: top) {
--top: yes;
}
@container scroll-state(direction: bottom) {
--bottom: yes;
}
@container scroll-state(direction: left) {
--left: yes;
}
@container scroll-state(direction: right) {
--right: yes;
}
@container scroll-state(direction: none) {
--none: yes;
}
}
</style>
<div id="scroller">
<div id="filler">
<div id="target"></div>
</div>
</div>
<script>
setup(() => assert_implements_scroll_state_container_queries());
promise_test(async t => {
await waitForAnimationFrames(2);
assert_equals(getComputedStyle(target).getPropertyValue("--none"), "yes");
assert_equals(getComputedStyle(target).getPropertyValue("--left"), "no");
assert_equals(getComputedStyle(target).getPropertyValue("--right"), "no");
assert_equals(getComputedStyle(target).getPropertyValue("--top"), "no");
assert_equals(getComputedStyle(target).getPropertyValue("--bottom"), "no");
}, "Check that scroll-state(direction) state before scrolling");
promise_test(async t => {
scroller.scrollBy(300, 0);
await waitForAnimationFrames(2);
scroller.scrollBy(0, 100);
await waitForAnimationFrames(2);
assert_equals(getComputedStyle(target).getPropertyValue("--left"), "no");
assert_equals(getComputedStyle(target).getPropertyValue("--right"), "yes");
assert_equals(scroller.scrollLeft, 300);
assert_equals(scroller.scrollTop, 100);
}, "Check that scroll-state(direction) horizontal state is persisted across vertical scroll event");
promise_test(async t => {
scroller.scrollBy(0, 100);
await waitForAnimationFrames(2);
scroller.scrollBy(0, -100);
await waitForAnimationFrames(2);
scroller.scrollBy(-200, 0);
await waitForAnimationFrames(2);
assert_equals(getComputedStyle(target).getPropertyValue("--top"), "yes");
assert_equals(getComputedStyle(target).getPropertyValue("--bottom"), "no");
assert_equals(scroller.scrollLeft, 100);
assert_equals(scroller.scrollTop, 100);
}, "Check that scroll-state(direction) vertical state is persisted across horizontal scroll event");
</script>