-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Expand file tree
/
Copy pathempty-pseudo-in-has-display-none.html
More file actions
113 lines (96 loc) · 3.52 KB
/
empty-pseudo-in-has-display-none.html
File metadata and controls
113 lines (96 loc) · 3.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<!DOCTYPE html>
<meta charset="utf-8">
<title>CSS Selectors Invalidation: :empty in :has() with display:none</title>
<link rel="author" title="Simon Fraser" href="smfr@apple.com">
<link rel="help" href="https://drafts.csswg.org/selectors/#relational">
<link rel="help" href="https://drafts.csswg.org/selectors/#empty-pseudo">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
#subject {
color: green;
}
#subject:has(:empty) {
display: none;
}
</style>
<div id="subject">
<p>This should be visible after the child div gets content.</p>
<div id="child"></div>
</div>
<script>
const subject = document.getElementById("subject");
const child = document.getElementById("child");
function testVisibility(test_name, expectVisible) {
test(function() {
const rect = subject.getBoundingClientRect();
if (expectVisible) {
assert_not_equals(getComputedStyle(subject).display, "none", "display should not be none");
assert_greater_than(rect.width, 0, "width should be greater than 0");
assert_greater_than(rect.height, 0, "height should be greater than 0");
} else {
assert_equals(getComputedStyle(subject).display, "none", "display should be none");
}
}, test_name);
}
testVisibility("Initially hidden because #child is :empty", false);
child.textContent = "text";
testVisibility("Visible after inserting text into #child", true);
{
let inner = document.createElement("div");
child.appendChild(inner);
}
testVisibility("Hidden after inserting empty element into #child", false);
child.textContent = "text";
testVisibility("Visible after inserting text into empty #child", true);
child.replaceChildren();
testVisibility("Hidden again after removing all children from #child", false);
child.textContent = "text";
testVisibility("Visible again after inserting text into empty #child", true);
child.textContent = "";
testVisibility("Hidden again after clearing text from #child", false);
{
let inner = document.createElement("div");
inner.textContent = "content";
child.appendChild(inner);
}
testVisibility("Visible after inserting non-empty element into #child", true);
</script>
<!-- Test :has(:not(:empty)) with display:none -->
<style>
#subject2 {
display: none;
}
#subject2:has(:not(:empty)) {
display: block;
}
</style>
<div id="subject2">
<div id="child2"></div>
</div>
<script>
{
const subject2 = document.getElementById("subject2");
const child2 = document.getElementById("child2");
function testVisibility2(test_name, expectVisible) {
test(function() {
if (expectVisible) {
assert_not_equals(getComputedStyle(subject2).display, "none", "display should not be none");
} else {
assert_equals(getComputedStyle(subject2).display, "none", "display should be none");
}
}, test_name);
}
testVisibility2(":not(:empty) - Initially hidden because #child2 is :empty", false);
child2.textContent = "text";
testVisibility2(":not(:empty) - Visible after inserting text into #child2", true);
child2.textContent = "";
testVisibility2(":not(:empty) - Hidden after clearing text from #child2", false);
child2.textContent = "text";
testVisibility2(":not(:empty) - Visible again after inserting text into #child2", true);
child2.replaceChildren();
testVisibility2(":not(:empty) - Hidden after removing all children from #child2", false);
child2.appendChild(document.createElement("div"));
testVisibility2(":not(:empty) - Visible after inserting element into #child2", true);
}
</script>