Skip to content
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

How to use global styles with this module #96

Open
kkorada opened this issue Nov 27, 2020 · 3 comments
Open

How to use global styles with this module #96

kkorada opened this issue Nov 27, 2020 · 3 comments

Comments

@kkorada
Copy link

kkorada commented Nov 27, 2020

Hi, In my app we are using styled components, fontawsome and some global styles. fontawsome and global styles are being attached to head. Is there any way I can attach them inside shadow root ?

For global css imports I tried configuring with style-loader insert option but it requires shadow root to be available before hand.

Can the styleSheets prop on root be helpful in this case ? How to use this prop ?

@kkorada
Copy link
Author

kkorada commented Dec 1, 2020

any update ?

@nirtamir2
Copy link

nirtamir2 commented May 16, 2021

Hi @kkorada
I had the same issue and I solved it with:

const sheet = new CSSStyleSheet();
sheet.addRule("*", `box-sizing: border-box`);
const styleSheets = [sheet];

export function Root() {
  return (
    <root.div styleSheets={styleSheets}>
      <App />
    </root.div>
  );
}

I don't know if it's the best way to handle it - if someone finds a more elegant way I will be happy to hear.

Update:

I notice that Firefox does not support the CSSStyleSheet constructor. So I found a better way (css is imported with @emotion/react):

      <root.div>
        <style>
          {
            css`* {
              box-sizing: border-box;
            }`.styles
          }
        </style>
        <InnerApp {...props} />
      </root.div>

Those styles are accessible for all the styles inside the root.

@husayt
Copy link

husayt commented Dec 14, 2022

Also, one could use a polyfill for CSSStyleSheet
https://github.com/calebdwilliams/construct-style-sheets

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants