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 add style element to web component #165

Open
Lionardo opened this issue Jan 19, 2024 · 0 comments
Open

how to add style element to web component #165

Lionardo opened this issue Jan 19, 2024 · 0 comments

Comments

@Lionardo
Copy link

I have a use case in which I need to pass a style element to the web component like this:
But it doesn't work. If shadow option is set to open or closed it doesn't matter.
I need to encapsulate styles during runtime that will be loaded over a request.
If this doesn't work what could be the alternative?

const ChatWebComponent = r2wc(Chat, {
  props: {
    Id: "string",
  },
} as any);

customElements.define("my-chat", ChatWebComponent);
const chat = document.createElement("my-chat");
chat.Id = "5896045a";
const style = document.createElement('style');

style.textContent = `
    #my-chat {
      font-family: "Roboto" !important;
      // some more styles...
    }
`;

// Append the style element to the shadow root.
chat.shadowRoot.appendChild(style);`
document.body.appendChild(chat);
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

1 participant