platosha / angular-polymer

Angular 2 support for Polymer elements
https://www.npmjs.com/package/angular-polymer
Apache License 2.0
220 stars 44 forks source link

custom-style causing issues with @angular2-material library #64

Open jaichandra opened 8 years ago

jaichandra commented 8 years ago

In apps which already use @angular2-material library, using polymer elements with angular2-polymer breaks material library css styles.

below line is causing issue:

PolymerDomAdapter.prototype.createStyleElement = function (css, doc) {
        if (doc === void 0) { doc = document; }
        var style = doc.createElement.call(doc, 'style', 'custom-style');
        this.appendChild(style, this.createTextNode(css));
        return style;
    };

Because the above code uses prototype and overrides the default createStyleElement function, it causes all styles to be converted to <style is="custom=style"> tags, thus breaking existing material library styles. Is there a work around for this?

Saulis commented 8 years ago

Can't see any workarounds – this function should probably be refined a bit to create custom-style elements only when css has Polymer css mixins or properties present.

Splaktar commented 8 years ago

I have been seeing issues with material2 styles and it looks like this is the culprit. It's unfortunate that this is still sitting here unassigned :(

@Saulis Do you know how to detect if the css "has Polymer css mixins or properties present"? I'm guessing that this would need something more than just looking for @apply and CSS Variables? But wouldn't inspecting all of the contents of the style element come at a performance cost?

We've had to re-declare our material2 styles inside of Angular components to get them to work again. It's pretty ugly.

Splaktar commented 8 years ago

Actually, I debugged my issues further and with or without the is="custom-style" there was no change in behavior or Material2 styles. I found that I needed to configure Material2's new theming system for my app. After that, everything is working as expected with styling.

jaichandra commented 8 years ago

@splaktar can you share some details on how you configured material theming system to get it to work with polymer? Would be very helpful.

logvi commented 7 years ago

The same issue for me. Can you please describe how to solve it?

Splaktar commented 7 years ago

@jaichandra @logvi you can see the repo here and I have a blog post about upgrading from Angular 2 RC.4 and getting this working again here.

logvi commented 7 years ago

@Splaktar Hm, it doesn't help me :(. I added custom theme but styles still overwritten by is="custom-style"

Splaktar commented 7 years ago

@logvi the styles aren't overwritten, they just get the is="custom-style" attribute added to them. It doesn't break anything for me. What problem are you seeing exactly?