-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Expand file tree
/
Copy pathmixin-shadow-dom.html
More file actions
115 lines (106 loc) · 3.13 KB
/
mixin-shadow-dom.html
File metadata and controls
115 lines (106 loc) · 3.13 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
114
115
<!DOCTYPE html>
<html>
<head>
<title>CSS Mixins: Shadow DOM</title>
<link rel="help" href="https://drafts.csswg.org/css-mixins-1/#defining-mixins">
<link rel="help" href="https://drafts.csswg.org/css-shadow-1/#css-tree-scoped-name">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<style>
@mixin --exists-only-outside-shadow() {
@result {
color: green;
}
}
</style>
<div id="host1">
<template shadowrootmode="open">
<style>
#e1 {
color: red;
@apply --exists-only-outside-shadow;
}
</style>
<div id="e1">This text should be green.</div>
</template>
</div>
<script>
test(() => {
let target = document.getElementById('host1').shadowRoot.getElementById('e1');
assert_equals(getComputedStyle(target).color, 'rgb(0, 128, 0)');
}, 'Style in shadow DOM should have access to outside non-adopted mixins');
</script>
<div id="host2">
<template shadowrootmode="open">
<style>
#e2 {
color: red;
@apply --m1;
}
</style>
<style>
@mixin --m1() {
@result {
color: green;
}
}
</style>
<div id="e2">This text should be green.</div>
</template>
</div>
<script>
test(() => {
let target = document.getElementById('host2').shadowRoot.getElementById('e2');
assert_equals(getComputedStyle(target).color, 'rgb(0, 128, 0)');
}, 'Style in shadow DOM should have access to inside mixins');
</script>
<style>
</style>
<div id="host3">
<template shadowrootmode="open">
<style>
#e3 {
color: red;
@apply --exists-only-in-adopted;
}
</style>
<div id="e3">This text should be green.</div>
</template>
</div>
<script>
test(() => {
const sheet = new CSSStyleSheet();
sheet.replaceSync('@mixin --exists-only-in-adopted() { @result { color: green; } }');
document.getElementById('host3').shadowRoot.adoptedStyleSheets = [sheet];
let target = document.getElementById('host3').shadowRoot.getElementById('e3');
assert_equals(getComputedStyle(target).color, 'rgb(0, 128, 0)');
}, 'Style in shadow DOM should have access to mixins from adopted stylesheets');
</script>
<div id="host4">
<template shadowrootmode="open">
<style>
@mixin --in-shadow() {
@result {
color: red;
}
}
</style>
</template>
</div>
<style>
#e4 {
color: green;
@apply --in-shadow;
}
</style>
<div id="e4">This text should be green.</div>
<script>
test(() => {
let target = document.getElementById('e4');
assert_equals(getComputedStyle(target).color, 'rgb(0, 128, 0)');
}, 'Style outside shadow DOM should _not_ have access to inside mixins');
</script>
</body>
</html>