Skip to content

Commit

Permalink
Allow adding type="custom" to avoid deprecation warning. Fixes #5017
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinpschaaf committed Jan 5, 2018
1 parent d8fafab commit fb522f6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
14 changes: 10 additions & 4 deletions lib/elements/custom-style.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
(function() {
'use strict';

const attr = 'include';

const INCLUDE = 'include';
const TYPE = 'type';

const CustomStyleInterface = window.ShadyCSS.CustomStyleInterface;

/**
Expand Down Expand Up @@ -86,9 +87,9 @@
return null;
}
this._style = style;
const include = style.getAttribute(attr);
const include = style.getAttribute(INCLUDE);
if (include) {
style.removeAttribute(attr);
style.removeAttribute(INCLUDE);
style.textContent = Polymer.StyleGather.cssFromModules(include) + style.textContent;
}
/*
Expand All @@ -102,6 +103,11 @@
cases of ordering w.r.t the main document styles.
*/
if (this.ownerDocument !== window.document) {
// Allow users to add `type="custom"` to <style> tags to avoid deprecation warning
const type = style.getAttribute(TYPE);
if (type == 'custom') {
style.removeAttribute(TYPE);
}
window.document.head.appendChild(this);
}
return this._style;
Expand Down
4 changes: 2 additions & 2 deletions test/unit/custom-style-import.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@

<link rel="import" href="sub/style-import.html">

<custom-style>
<custom-style id="type-was-custom">
<style is="custom-style" include="shared-style style-import
style-import2">
style-import2" type="custom">
html {

--import-mixin: {
Expand Down
6 changes: 6 additions & 0 deletions test/unit/custom-style.html
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,12 @@
assertComputed(m, '4px');
});

test('imported custom-style style with type="custom" has type removed', function() {
const customStyle = document.head.querySelector('custom-style#type-was-custom');
const style = customStyle.querySelector('style');
assert.isFalse(style.hasAttribute('type'));
});

test('dynamic custom-styles apply', function() {
var dynamic = document.querySelector('.dynamic');
assertComputed(dynamic, '0px');
Expand Down

0 comments on commit fb522f6

Please sign in to comment.