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

tailwind is not working with slots & shadow true #191

Open
praveens96 opened this issue Aug 16, 2024 · 2 comments
Open

tailwind is not working with slots & shadow true #191

praveens96 opened this issue Aug 16, 2024 · 2 comments

Comments

@praveens96
Copy link

I am trying to use tailwind css with my react components and want to convert them to web components for my library.

The issue is, when i want the children in react to work, i need to set the shadow: "open" while generating web component.
But, if i set that, tailwind styles are not working.

If i remove shadow: "open" , tailwind styles do work but slots i.e. children are not being shown.

can you help here?

@tema3210
Copy link

tema3210 commented Sep 3, 2024

the shadow tree get's its own CSS scope, so you just don't have your styles there, so if you want your css you cannot use shadow DOM, can you?

@shyqerigashi
Copy link

@praveens96 I had the same issue but what you can do is create a wrapper component for your react component and there you can inject the tailwindcss file. I know that this means you have multiple tailwindcss imports but browser nowadays they load this only once the same CSS file (you can verify it under inspect > network).

export function WebComponentWrapper(Component: React.FC<any>) {
  return (props: any) => {
    return (
      <>
        <link
          rel="stylesheet"
          href="/path/to/your/index.css"
        />
        <Component {...props}>
          <slot />
        </Component>
      </>
    );
  };
}

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