Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 8e67ee2

Browse files
xiaochenghmoz-wptsync-bot
authored andcommitted
Bug 1828506 [wpt PR 39576] - [anchor-position] Update layout on anchor attribute changes, a=testonly
Automatic update from web-platform-tests [anchor-position] Update layout on anchor attribute changes This patch also adds WPTs for the anchor attribute (without popovers) to support the HTML PR whatwg/html#9144 Fixed: 1432016 Change-Id: I3e80326268008e6beaf74389bb32c01050406a81 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4434155 Commit-Queue: Joey Arhar <[email protected]> Commit-Queue: Xiaocheng Hu <[email protected]> Reviewed-by: Joey Arhar <[email protected]> Code-Coverage: Findit <[email protected]> Auto-Submit: Xiaocheng Hu <[email protected]> Cr-Commit-Position: refs/heads/main@{#1131479} -- wpt-commits: db5d9506cb37895b200037877628911afd3fac14 wpt-pr: 39576
1 parent d2e7b8b commit 8e67ee2

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<!DOCTYPE html>
2+
<link rel="help" href="https://github.com/whatwg/html/pull/9144">
3+
<link rel="author" href="mailto:[email protected]">
4+
<script src="/resources/testharness.js"></script>
5+
<script src="/resources/testharnessreport.js"></script>
6+
7+
<style>
8+
body {
9+
margin: 0;
10+
}
11+
#anchor {
12+
width: 100px;
13+
height: 100px;
14+
margin-left: 50px;
15+
margin-top: 50px;
16+
background: orange;
17+
}
18+
#target {
19+
position: absolute;
20+
left: anchor(right);
21+
top: anchor(top);
22+
width: 100px;
23+
height: 100px;
24+
background: lime;
25+
}
26+
</style>
27+
<div id="anchor"></div>
28+
<div id="target" anchor="anchor"></div>
29+
30+
<script>
31+
test(() => {
32+
assert_equals(target.offsetLeft, 150);
33+
assert_equals(target.offsetTop, 50);
34+
}, 'The anchor attribute should position the target element next to its implicit anchor');
35+
36+
test(() => {
37+
assert_equals(target.anchorElement, anchor);
38+
}, 'The element.anchorElement IDL should reflect the element pointed to by the anchor attribute');
39+
</script>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<!DOCTYPE html>
2+
<link rel="help" href="https://github.com/whatwg/html/pull/9144">
3+
<link rel="author" href="mailto:[email protected]">
4+
<script src="/resources/testharness.js"></script>
5+
<script src="/resources/testharnessreport.js"></script>
6+
7+
<style>
8+
body {
9+
margin: 0;
10+
}
11+
.anchor {
12+
width: 100px;
13+
height: 100px;
14+
margin-left: 50px;
15+
margin-top: 50px;
16+
background: orange;
17+
}
18+
.target {
19+
position: absolute;
20+
left: anchor(right, 123px);
21+
top: anchor(top, 456px);
22+
width: 100px;
23+
height: 100px;
24+
background: lime;
25+
}
26+
</style>
27+
<div class="anchor" id="anchor1"></div>
28+
<div class="anchor" id="anchor2"></div>
29+
<div class="target" id="target1" anchor="anchor1"></div>
30+
<div class="target" id="target2" anchor="anchor1"></div>
31+
32+
<script>
33+
test(() => {
34+
document.body.offsetLeft; // Force layout
35+
target1.setAttribute('anchor', 'anchor2');
36+
assert_equals(target1.offsetLeft, 150);
37+
assert_equals(target1.offsetTop, 200);
38+
39+
target1.setAttribute('anchor', 'anchor1');
40+
assert_equals(target1.offsetLeft, 150);
41+
assert_equals(target1.offsetTop, 50);
42+
}, 'Layout should be updated when anchor attribute changes to another element');
43+
44+
test(() => {
45+
document.body.offsetLeft; // Force layout
46+
target2.setAttribute('anchor', 'nonexist-anchor');
47+
assert_equals(target2.offsetLeft, 123);
48+
assert_equals(target2.offsetTop, 456);
49+
}, 'Layout should be updated when anchor attribute changes to a non-existent element');
50+
</script>

0 commit comments

Comments
 (0)