Skip to content

Reapply "Support @contents in mixins." #54148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions css/css-mixins/contents-rule.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<!DOCTYPE html>
<html>
<head>
<title>CSS Mixins: Mixins depending on other mixins</title>
<link rel="help" href="https://drafts.csswg.org/css-mixins-1/#apply-rule">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
@mixin --m1(@contents) {
@contents;
}
#e1 {
color: red;
@apply --m1 { color: green; }
}

@mixin --m2(@contents) {
@contents
}
#e2 {
color: red;
@apply --m1 { color: green; }
}

@mixin --m3(@contents) {
&.a {
@contents { color: blue; }
}
}
.b {
color: red;
@apply --m3 { color: green; }
}

@mixin --m4(@contents) {
&.c {
@contents { color: green; }
}
}
.d {
color: red;
@apply --m4;
}

@mixin --m5 {
@contents { color: red !important; }
color: green;
}
#e4 {
@apply --m5 { color: red !important; }
}
</style>
</head>
<body>
<div id="e1">This text should be green.</div>
<div id="e2">This text should be green.</div>
<div class="a b" id="e3">This text should be green.</div>
<div class="c d" id="e4">This text should be green.</div>
<div id="e5">This text should be green.</div>
<script>
test(() => {
let target = document.getElementById('e1');
assert_equals(getComputedStyle(target).color, 'rgb(0, 128, 0)');
}, 'Simple @contents with no fallback');

test(() => {
let target = document.getElementById('e2');
assert_equals(getComputedStyle(target).color, 'rgb(0, 128, 0)');
}, 'Implicit semicolon after @contents, at end of block');

test(() => {
let target = document.getElementById('e3');
assert_equals(getComputedStyle(target).color, 'rgb(0, 128, 0)');
}, 'Block in @apply overrides fallback');

test(() => {
let target = document.getElementById('e4');
assert_equals(getComputedStyle(target).color, 'rgb(0, 128, 0)');
}, 'Fallback is used if @apply has no block');

test(() => {
let target = document.getElementById('e5');
assert_equals(getComputedStyle(target).color, 'rgb(0, 128, 0)');
}, '@contents is ignored if there is no @contents parameter');
</script>
</body>
</html>