Fix for :global(...) styles in custom elements. Close #2969

pull/4121/head
Mikhail Podgurskiy 6 years ago
parent 1ef7601d69
commit ec12b99c92

@ -442,7 +442,7 @@ export default function dom(
constructor(options) { constructor(options) {
super(); super();
${css.code && b`this.shadowRoot.innerHTML = \`<style>${css.code.replace(/\\/g, '\\\\')}${options.dev ? `\n/*# sourceMappingURL=${css.map.toUrl()} */` : ''}</style>\`;`} ${css.code && b`this.shadowRoot.innerHTML = \`<style>${css.code.replace(/\\/g, '\\\\').replace(/:global\(([-.\w]+)\)/g, '$1')}${options.dev ? `\n/*# sourceMappingURL=${css.map.toUrl()} */` : ''}</style>\`;`}
@init(this, { target: this.shadowRoot }, ${definition}, ${has_create_fragment ? 'create_fragment': 'null'}, ${not_equal}, ${prop_indexes}, ${dirty}); @init(this, { target: this.shadowRoot }, ${definition}, ${has_create_fragment ? 'create_fragment': 'null'}, ${not_equal}, ${prop_indexes}, ${dirty});

@ -0,0 +1,9 @@
<svelte:options tag="custom-element"/>
<style>
:global(p.active) {
color:rgb(128, 128, 128);
}
</style>
<p></p>

@ -0,0 +1,12 @@
import * as assert from 'assert';
import CustomElement from './main.svelte';
export default function (target) {
new CustomElement({
target
});
const style = target.querySelector('custom-element').shadowRoot.querySelector('style');
assert.equal(style.textContent, 'p.active{color:rgb(128, 128, 128)}');
}
Loading…
Cancel
Save