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

imported css modules should always be before element's styles #4778

Merged
merged 1 commit into from
Aug 7, 2017
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
4 changes: 2 additions & 2 deletions lib/mixins/element-mixin.html
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,8 @@
function finalizeTemplate(proto, template, baseURI, is, ext) {
// support `include="module-name"`
let cssText =
Polymer.StyleGather.cssFromTemplate(template, baseURI) +
Polymer.StyleGather.cssFromModuleImports(is);
Polymer.StyleGather.cssFromModuleImports(is) +
Polymer.StyleGather.cssFromTemplate(template, baseURI);
if (cssText) {
let style = document.createElement('style');
style.textContent = cssText;
Expand Down
23 changes: 14 additions & 9 deletions lib/utils/style-gather.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,13 @@
cssFromModule(moduleId) {
let m = importModule(moduleId);
if (m && m._cssText === undefined) {
let cssText = '';
// module imports: <link rel="import" type="css">
let cssText = this._cssFromModuleImports(m);
// include css from the first template in the module
let t = m.querySelector('template');
if (t) {
cssText += this.cssFromTemplate(t, /** @type {templateWithAssetPath }*/(m).assetpath);
cssText += this.cssFromTemplate(t, /** @type {templateWithAssetPath} */(m).assetpath);
}
// module imports: <link rel="import" type="css">
cssText += this.cssFromModuleImports(moduleId);
m._cssText = cssText || null;
}
if (!m) {
Expand Down Expand Up @@ -126,12 +125,18 @@
* @this {StyleGather}
*/
cssFromModuleImports(moduleId) {
let cssText = '';
let m = importModule(moduleId);
if (!m) {
return cssText;
}
let p$ = m.querySelectorAll(MODULE_STYLE_LINK_SELECTOR);
return m ? this._cssFromModuleImports(m) : '';
},
/**
* @memberof Polymer.StyleGather
* @this {StyleGather}
* @param {!HTMLElement} module dom-module element that could contain `<link rel="import" type="css">` styles
* @return {string} Concatenated CSS content from links in the dom-module
*/
_cssFromModuleImports(module) {
let cssText = '';
let p$ = module.querySelectorAll(MODULE_STYLE_LINK_SELECTOR);
for (let i=0; i < p$.length; i++) {
let p = p$[i];
if (p.import) {
Expand Down
25 changes: 25 additions & 0 deletions test/unit/styling-import.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,23 @@
</script>
</dom-module>

<dom-module id="x-import-order">
<link rel="import" type="css" href="styling-import2.css">
<template>
<style>
#two {
border: 1px solid black;
}
</style>
<div id="two"></div>
</template>
<script>
HTMLImports.whenReady(function() {
Polymer({is: 'x-import-order'});
})
</script>
</dom-module>


<script>
suite('style-imports', function() {
Expand Down Expand Up @@ -85,6 +102,14 @@

});

test('styles included via link rel="import" type="css" are overridden by styles in template', function() {
var el = document.createElement('x-import-order');
document.body.appendChild(el);
Polymer.flush();
assertComputed(el.$.two, '1px');
document.body.removeChild(el);
});

});

</script>
Expand Down