Skip to content
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

Includes element defaults in the list of own properties by which elements are styled. #1891

Merged
merged 1 commit into from
Jun 17, 2015
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions src/lib/style-properties.html
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@
var m;
while (m = this.rx.VAR_CAPTURE.exec(cssText)) {
props[m[1]] = true;
var def = m[2];
if (def && def.match(this.rx.IS_VAR)) {
props[def] = true;
}
}
},

Expand Down Expand Up @@ -336,6 +340,7 @@
// var(--a, fallback-literal(with-one-nested-parens))
VAR_MATCH: /(^|\W+)var\([\s]*([^,)]*)[\s]*,?[\s]*((?:[^,)]*)|(?:[^;]*\([^;)]*\)))[\s]*?\)/gim,
VAR_CAPTURE: /\([\s]*(--[^,\s)]*)(?:,[\s]*(--[^,\s)]*))?(?:\)|,)/gim,
IS_VAR: /^--/,
BRACKETED: /\{[^}]*\}/g,
HOST_PREFIX: '(?:^|[^.])',
HOST_SUFFIX: '($|[.:[\\s>+~])'
Expand Down
32 changes: 32 additions & 0 deletions test/unit/styling-cross-scope-var.html
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,26 @@
</script>
</dom-module>

<dom-module id="x-has-def">
<style>
:host {
border: var(--border, --defaultBorder);
margin: 8px;
padding: 8px;
display: block;
}
</style>

<template>
Element with default variable.
</template>
<script>
HTMLImports.whenReady(function() {
Polymer({is: 'x-has-def'});
});
</script>
</dom-module>

<dom-module id="x-has-if">
<style>
.iffy {
Expand Down Expand Up @@ -254,6 +274,7 @@
--default1: var(--undefined, 6px solid yellow);
--default2: var(--undefined, --fallback);
--default3: var(--undefined, rgb(128, 200, 250));
--defaultBorder: 22px solid green;
--a: 10px;
--b: 5px;
--primary-color: rgb(128, 128, 128);
Expand Down Expand Up @@ -297,6 +318,10 @@
background-color: var(--default3);
}

#defaultElement2 {
--defaultBorder: 23px solid goldenrod;
}

#overrides1a, #overrides1b, #overrides2 {
--rename: 8px solid navy;
}
Expand Down Expand Up @@ -341,6 +366,8 @@
<div id="default1">default</div>
<div id="default2">var default</div>
<div id="default3">tricky property rgb(...) default</div>
<x-has-def id="defaultElement1"></x-has-def>
<x-has-def id="defaultElement2"></x-has-def>
<div id="applyDefault1">default</div>
<div id="applyDefault2">var default</div>
<div id="calc">Calc</div>
Expand Down Expand Up @@ -503,6 +530,11 @@
test('pseudo-elements can consume custom properties', function() {
assertComputed(styled.$.after, '17px', '::after');
});

test('elements using only variable defaults are styled properly', function() {
assertComputed(styled.$.defaultElement1, '22px');
assertComputed(styled.$.defaultElement2, '23px');
});

});

Expand Down