Replies: 2 comments 1 reply
-
Hello, To add compatibility for the Shadow DOM, you can modify the Tailwind configuration to include :host in addition to :root. Here's how you can approach it: Customizing the Tailwind Configuration: In your tailwind.config.js file, you can extend Tailwind's CSS variables to be included in both :root and :host. You might need to write a custom PostCSS plugin or use Tailwind's @layer to ensure this gets applied. Using PostCSS with Tailwind (or Tailwind Plugin): You can customize the @theme layer to prepend :root, :host like this: js Ensure Tailwind's CSS is Applied in Shadow DOM: When you generate your Web Component, ensure that the generated CSS is encapsulated within the component's shadow root. Here's a basic example: jsx class MyComponent extends HTMLElement { customElements.define('my-component', MyComponent); |
Beta Was this translation helpful? Give feedback.
-
There was a similar question asked in the Discord server with a maintainer response as follows:
|
Beta Was this translation helpful? Give feedback.
-
Hello,
I'm using Tailwind v4 with Vite on a project where I want to create Web Component using React and Tailwind for the styles.
I noticed that all the CSS Variables included on the @theme layer are inside a ":root" selector, as is mentioned on the Tailwind v4.0 Beta Documentation:
I would be great if all the theme variables are included using ":root, :host" selector for Shadow DOM compatibility. Example:
You can check why on this article:
https://techblog.skeepers.io/create-a-web-component-from-a-react-component-bbe7c5f85ee6
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions