Open bjornharvold opened 4 years ago
Hi!
Thanks for being part of the Font Awesome Community.
Sorry, can't help.
Leaving this open for feedback from the community
Thanks. I am also a pro subscriber. Should I be asking for support differently?
@bjornharvold you can also post in the font awesome pro repository, but please keep this post open because this is a public repo
@bjornharvold Could you figure out a solution ? I'm facing the same issue.
@hichem-code-it No solution. Font Awesome does not yet like to live within Shadow DOM and Web Components.
Thks for you answer, so the only possible solution I found yet, is to import the font awesome style sheet, directly in the component. It will duplicate it for each component though.
Reference: https://fontawesome.com/how-to-use/javascript-api/setup/configuration
@fortawesome/fontawesome-svg-core
has a config object.
You can disable the autoAddCss
feature through this in the following way:
import { config } from '@fortawesome/fontawesome-svg-core';
config.autoAddCss = false;
The CSS is now no longer automatically injected into the head tag. You can now include the styling in your component's css, causing it to get scoped in the shadowDOM:
@import "@fortawesome/fontawesome-svg-core/styles.css";
.
Do note the autoAddCss
feature needs to be enabled for other props to be taken into account such as replacementClass
as it internally uses a function called css()
which is no longer being called now because we just import the css directly. https://github.com/FortAwesome/Font-Awesome/blob/master/js-packages/@fortawesome/fontawesome-svg-core/index.js#L2092
Exporting the css function would actually be a good thing for such a case I believe? @tagliala
Thank you so much @miniplus that's the perfect solution for this problem
The library should not reference the document
global when attaching the styles but instead it should use the root element’s ownerDocument
property. This fixes all sorts of situations where globalThis.document !== icon.ownerDocument
:
document
global)There's also a unsolved 2014 issue requesting this and a couple more:
Absolutely 100% what @fregante said. That would be the perfect solution.
Hi,
My goal is to create a bunch of Web Components with Shadow DOM enabled so they can be easily embedded into other sites. I have been having a lot of issues with getting font-awesome to work.
Here is an attempt by someone else at solving this issue: https://github.com/e-kursy-it/blog/tree/master/fa-icon
I haven't created Web Components yet. I am starting with Shadow DOM. The moment I set encapsulation to ShadowDom in my Angular component, sizing is lost and will scale to the width of whatever container it is in. Not sure if it relates to:
https://github.com/FortAwesome/Font-Awesome/issues/15449
Please advise. Angular Material icons work within Web Components when using something like mat-icon-button. However, font-awesome icons are just A LOT better!
Guessing my request is to make fa-icon work with the Web Component standard.
Stackblitz: https://stackblitz.com/edit/angular-qec7bz