Skip to content

Commit 21f8dfd

Browse files
authored
1 parent 2aa7252 commit 21f8dfd

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<!DOCTYPE html>
2+
<meta charset="utf-8">
3+
<title>:has() invalidation when :has() is in a non-subject compound of an enclosing :is()</title>
4+
<link rel="help" href="https://drafts.csswg.org/selectors/#relational">
5+
<script src="/resources/testharness.js"></script>
6+
<script src="/resources/testharnessreport.js"></script>
7+
<style>
8+
div { color: grey }
9+
/* :has() sits in the leftmost (ancestor) compound of the :is() argument; the actual
10+
has-bearer is some ancestor of #outer, not #outer itself. */
11+
#outer:is(:has(.test) .outer) #subject { color: red }
12+
</style>
13+
<div>
14+
<div id="trigger">
15+
<div id="outer" class="outer">
16+
<div id="subject"></div>
17+
</div>
18+
</div>
19+
</div>
20+
<script>
21+
const grey = 'rgb(128, 128, 128)';
22+
const red = 'rgb(255, 0, 0)';
23+
24+
test(() => {
25+
assert_equals(getComputedStyle(subject).color, grey);
26+
}, 'initial: #subject is grey');
27+
28+
test(() => {
29+
const testElement = document.createElement('div');
30+
testElement.className = 'test';
31+
trigger.appendChild(testElement);
32+
assert_equals(getComputedStyle(subject).color, red);
33+
}, 'insert .test under #trigger: #subject becomes red');
34+
35+
test(() => {
36+
trigger.querySelector('.test').remove();
37+
assert_equals(getComputedStyle(subject).color, grey);
38+
}, 'remove .test: #subject returns to grey');
39+
</script>

0 commit comments

Comments
 (0)