-
-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IE11 Support #11
Comments
Hey there! Thanks for opening up this issue. I think the |
You are correct, it should be in |
@Coly010 Thank you! I would very much appreciate that! |
Ok so I got this to work 🎉 But it's We don't need a polyfill, rather a ponyfill. The ponyfill I used was css-vars-ponyfill. It's super quick and isn't too big bundle size: 586 kB. One of the biggest reasons for using it was that it allows declaration of global css props. We also need to rewrite the The main reasoning behind this is due to IE11's restriction on the // HTML
<myElement>
</myElement>
// =========
// Set the style in JS
myElement.style = "--primary-color: blue; font-size: 18px;";
// Output in IE
// HTML
<myElement style="font-size: 18px">
</myElement> As we can see, we've lost the Therefore, I rewrote the const existingMethod = service['_setStyle'];
service['_setStyle'] = (vars: { name: string; val: string }[]) => {
existingMethod(vars);
const currentStyle = document.documentElement.getAttribute('data-mat-vars');
const style = vars.reduce(
(styleString: string, cssVar: { name: string; val: string }) => {
styleString += `${cssVar.name}:${cssVar.val};`;
return styleString;
},
currentStyle || ''
);
// Need to set a data attr for IE11 as it's style attr only allows for Style Attrs IE11 supports
document.documentElement.setAttribute('data-mat-vars', style);
}; The next step is to initialise the ponyfill. This should ideally be done after we call our const documentElement = document.documentElement;
if (documentElement.hasAttribute('data-mat-vars')) {
const customThemePropsString = documentElement.getAttribute('data-mat-vars');
const themeVariablesObj = {};
// Convert from string of css vars into key-value pair
customThemePropsString.split(';').forEach(prop => {
const propParts = prop.split(':');
themeVariablesObj[propParts[0]] = propParts[1];
});
// Let's init the ponyfill with our custom css variables
cssVars({
rootElement: document,
variables: themeVariablesObj,
watch: true
});
} And voila! The next step for improving this would be to have an Observable Subject in the service that when |
@Coly010 thank you very much for sharing! |
IE11 support has been deprecated in Angular v12 and removed in Angular v13, so this hack is obsolete now. |
Currently, as it stands, this library does not support IE11 as IE11 does not support CSS Variables.
A polyfill should fix this, and it may be more ideal to supply that polyfill with this library.
The text was updated successfully, but these errors were encountered: