Skip to content

Commit

Permalink
fix(styles): prevent wrapping Polymer scoped styles in <custom-style>
Browse files Browse the repository at this point in the history
Fixes #33
  • Loading branch information
hotforfeature committed Jun 13, 2017
1 parent 64ee2e6 commit 80775a6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
14 changes: 13 additions & 1 deletion src/style/shared-styles-host.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class TestComponent { }
})
class NativeComponent { }

describe('DomSharedCustomStylesHost', () => {
describe('PolymerDomSharedStylesHost', () => {
let fixture: ComponentFixture<TestComponent>;

beforeEach(() => {
Expand Down Expand Up @@ -88,4 +88,16 @@ describe('DomSharedCustomStylesHost', () => {
});
}));
}

it('should ignore <style> elements with scope attribute from Polymer', async(() => {
const scopeStyle = document.createElement('style');
scopeStyle.setAttribute('scope', 'my-element');
document.head.appendChild(scopeStyle);
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(document.head.querySelectorAll('custom-style').length).toBeGreaterThan(0);
expect(scopeStyle.parentElement).toBe(document.head);
document.head.removeChild(scopeStyle);
});
}));
});
5 changes: 3 additions & 2 deletions src/style/shared-styles-host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ export class PolymerDomSharedStylesHost extends DomSharedStylesHost {
private wrapStyleNodes() {
this.hostNodes.forEach(hostNode => {
Array.from(hostNode.childNodes).forEach(childNode => {
if ((<Element>childNode).tagName === 'STYLE') {
const childEle = childNode as Element;
if (childEle.tagName === 'STYLE' && !childEle.hasAttribute('scope')) {
const customStyleEl = this.document.createElement('custom-style');
hostNode.removeChild(childNode);
(<Element>childNode).setAttribute('is', 'custom-style');
childEle.setAttribute('is', 'custom-style');
customStyleEl.appendChild(childNode);
hostNode.appendChild(customStyleEl);
}
Expand Down

0 comments on commit 80775a6

Please sign in to comment.