Files
sousa-gecko/testing/web-platform/tests/css/css-anchor-position/anchor-fallback-scroll-axis.html
T
Vladimir Levin 307d89895c Bug 2047313 [wpt PR 60594] - anchor: Respect needs scroll anchor adjustment in axis, a=testonly
Automatic update from web-platform-tests
anchor: Respect needs scroll anchor adjustment in axis

This patch ensures that when dealing with remembered scroll offsets
we respect whether we need an adjustment in a particular axis.

If we don't, we don't include the adjustment in that axis.

R=ikilpatrick@chromium.org

Bug: 521929404
Change-Id: If49fc4dbc0a27b1d372247f5f8cd2c43a34e4e5d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7934209
Reviewed-by: Ian Kilpatrick <ikilpatrick@chromium.org>
Commit-Queue: Vladimir Levin <vmpstr@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1646802}

--

wpt-commits: b3097487d7ce5ef273fc65ded30c1b89e3081d71
wpt-pr: 60594
2026-06-18 14:39:17 +00:00

83 lines
2.2 KiB
HTML

<!DOCTYPE html>
<title>CSS Anchor Positioning: Fallback evaluation should only consider scroll adjustment axes</title>
<link rel="help" href="https://drafts.csswg.org/css-anchor-position-1/#scroll">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
body {
margin: 0;
}
#scroller {
overflow: scroll;
width: 400px;
height: 400px;
border: 1px solid black;
}
#spacer {
height: 1000px;
width: 1000px;
}
#anchor {
anchor-name: --anchor;
width: 100px;
height: 100px;
background: blue;
margin-top: 150px;
margin-left: 150px;
}
#anchored {
position: fixed;
position-anchor: --anchor;
right: anchor(left);
left: auto;
top: 150px;
width: 100px;
height: 100px;
background: red;
position-try-fallbacks: --fallback;
display: none; /* Hide initially */
}
@position-try --fallback {
background: green;
left: 0px;
right: auto;
}
</style>
<div id="scroller">
<div id="spacer">
<div id="anchor"></div>
</div>
</div>
<div id="anchored"></div>
<script>
promise_test(async () => {
const anchored = document.getElementById('anchored');
const scroller = document.getElementById('scroller');
// 1. Scroll scroller to Y=400 first.
scroller.scrollTop = 400;
await new Promise(resolve => requestAnimationFrame(resolve));
// 2. Show the element. Layout will happen at Y=400, X=0.
anchored.style.display = 'block';
await new Promise(resolve => requestAnimationFrame(resolve));
// Initial state: fits, should be at left 51.
assert_equals(anchored.getBoundingClientRect().left, 51, 'Initial left should be 51');
// 3. Scroll scroller horizontally by 300px.
// The anchor moves left, pushing the anchored element off-screen left.
// This should trigger the X fallback (move to left 0).
scroller.scrollLeft = 300;
// Wait for scroll and layout
await new Promise(requestAnimationFrame);
await new Promise(requestAnimationFrame);
assert_equals(anchored.getBoundingClientRect().left, 0, 'Left after scroll should be 0 (fallback)');
}, "Horizontal overflow fallback");
</script>