bitovi / bitovi/react-to-web-component

how to add style element to web component

Open
#165 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
TypeScript
Stars
944
Forks
52
PR merge metrics
No merged PRs in 30d

Description

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?

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

customElements.define("my-chat", ChatWebComponent);
```

```javascript
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);
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.