[go: nahoru, domu]

Skip to content

Commit

Permalink
[css-nesting] Make & in top-level rules behave like :scope.
Browse files Browse the repository at this point in the history
This was a recent and seemingly unannounced change to the spec.

Bug: 1095675
Change-Id: I9fec6ffe2f7f48ad1505772578127ad160038956
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4206786
Commit-Queue: Steinar H Gunderson <sesse@chromium.org>
Reviewed-by: Rune Lillesveen <futhark@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1100352}
  • Loading branch information
Steinar H. Gunderson authored and chromium-wpt-export-bot committed Feb 2, 2023
1 parent cfdf7a3 commit c82c735
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions css/css-nesting/nesting-basic-ref.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@
<div class="test"></div>
<div class="test"></div>
<div class="test"></div>
<div class="test"></div>
</body>
9 changes: 9 additions & 0 deletions css/css-nesting/nesting-basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@
background-color: green !important;
}

/* & at top level counts as :scope, i.e. the root element here */
& .test-12 {
background-color: green;
}
& > .test-12 {
background-color: red !important;
}

body * + * {
margin-top: 8px;
}
Expand All @@ -100,4 +108,5 @@
<div class="test test-9 t9-- t9-"><div></div></div>
<div class="test test-10"><div></div></div>
<div class="test test-11"><div></div></div>
<div class="test test-12"></div>
</body>
30 changes: 30 additions & 0 deletions css/css-nesting/top-level-is-scope.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!doctype html>
<title>Top-level & is treated like :scope</title>
<link rel="author" title="Steinar H. Gunderson" href="mailto:sesse@chromium.org">
<link rel="help" href="https://drafts.csswg.org/css-nesting-1/">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<div id="p">
<div class="match" id="level1">
<div class="match" id="level2"></div>
</div>
</div>

<script>
test(() => {
let matched = [];
for (const elem of p.querySelectorAll('& .match')) {
matched.push(elem.getAttribute('id'));
}
assert_array_equals(matched, ['level1', 'level2']);
}, '& as direct ancestor');

test(() => {
let matched = [];
for (const elem of p.querySelectorAll('& > .match')) {
matched.push(elem.getAttribute('id'));
}
assert_array_equals(matched, ['level1']);
}, '& matches scoped element only, not everything');
</script>

0 comments on commit c82c735

Please sign in to comment.