Skip to content
This repository has been archived by the owner on Sep 14, 2021. It is now read-only.

Commit

Permalink
Workaround Edge 15's broken CSS Custom Properties
Browse files Browse the repository at this point in the history
Fixes #111
  • Loading branch information
dfreedm committed Aug 8, 2017
1 parent 930c752 commit 74577b1
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 8 deletions.
2 changes: 1 addition & 1 deletion apply-shim.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apply-shim.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion custom-style-interface.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion custom-style-interface.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion scoping-shim.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion scoping-shim.min.js.map

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/style-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ function calcCssVariables(settings) {
// safari 9.1 has a recalc bug: https://bugs.webkit.org/show_bug.cgi?id=155782
// However, shim css custom properties are only supported with ShadyDOM enabled,
// so fall back on native if we do not detect ShadyDOM
nativeCssVariables = nativeShadow || Boolean(!navigator.userAgent.match('AppleWebKit/601') &&
// Edge 15: custom properties used in ::before and ::after will also be used in the parent element
// https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/12414257/
nativeCssVariables = nativeShadow || Boolean(!navigator.userAgent.match(/AppleWebKit\/601|Edge\/15/) &&
window.CSS && CSS.supports && CSS.supports('box-shadow', '0 0 0 var(--foo)'));
}
}
Expand Down
3 changes: 2 additions & 1 deletion tests/runner.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
'complicated-mixin-ordering.html',
'dynamic-scoping.html',
'settings.html',
'chrome-devtools.html'
'chrome-devtools.html',
'workarounds.html'
];
// http://eddmann.com/posts/cartesian-product-in-javascript/
function flatten(arr) { return [].concat.apply([], arr) }
Expand Down
58 changes: 58 additions & 0 deletions tests/workarounds.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<!DOCTYPE html>
<!--
@license
Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<html>

<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1, user-scalable=yes">
<script>
WCT = { waitFor: function (cb) { HTMLImports.whenReady(cb) } }
</script>
<script src="./test-flags.js"></script>
<script src="../../web-component-tester/browser.js"></script>
<script src="../../webcomponents-platform/webcomponents-platform.js"></script>
<script src="../../es6-promise/dist/es6-promise.auto.min.js"></script>
<script src="../../template/template.js"></script>
<script src="../../html-imports/html-imports.min.js"></script>
<script src="../../shadydom/shadydom.min.js"></script>
<script src="../../custom-elements/custom-elements.min.js"></script>
<script src="../scoping-shim.min.js"></script>
<script src="../apply-shim.min.js"></script>
<script src="../custom-style-interface.min.js"></script>
<script src="module/generated/make-element.js"></script>
</head>
<body>
<template id="x-bug">
<style>
:host {
--bg: rgb(255, 0, 0);
}
div::after {
content: 'test';
background-color: var(--bg);
}
</style>
<div></div>
</template>
<script>
suite('Workarounds', function() {
test('Edge 15', function() {
makeElement('x-bug');
let el = document.createElement('x-bug');
document.body.appendChild(el);
let div = el.shadowRoot.querySelector('div');
assert.notEqual(getComputedStyle(div).getPropertyValue('background-color').trim(), 'rgb(255, 0, 0)');
})
});
</script>
</body>
</html>

0 comments on commit 74577b1

Please sign in to comment.