Skip to content

Commit

Permalink
Merge pull request #1891 from Polymer/fix-1752
Browse files Browse the repository at this point in the history
Includes element defaults in the list of own properties by which elements are styled.
  • Loading branch information
kevinpschaaf committed Jun 17, 2015
2 parents e8169ec + 411e285 commit 6e2d238
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
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

0 comments on commit 6e2d238

Please sign in to comment.