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

CSS in custom element #2308

Open
07akioni opened this issue Jan 28, 2022 Discussed in #2301 · 1 comment
Open

CSS in custom element #2308

07akioni opened this issue Jan 28, 2022 Discussed in #2301 · 1 comment

Comments

@07akioni
Copy link
Collaborator

Discussed in #2301

Originally posted by jbmolle January 27, 2022
Hi,

I'm trying to create a custom element from a Vue component with Vue 3 function defineCustomElement.
Let say the component is just a NaiveUI Button.

The problem is that in a Vue app NButton works perfectly but in a custom element there is no CSS style applied.
Actually NButton uses useTheme which renders the CSS classes with css-render. useTheme uses style.mount which calls document.head.appendChild or document.head.insertBefore. So we get inline stylesheets in the head of the page. The problem with Vue3 custom elements is that a shadow root is automatically inserted and so everything inside the custom element doesn't have access to the stylesheets in head.
Would it be possible to add a custom variable to mount.ts with the dom element where the style should be inserted. So per default it would include to document.head but if we give a specific element, it would insert it in a style tag in the shadow root.

Let me know what you think and if you see another solution.
Thanks,
JB

@github-actions github-actions bot added the invalid This doesn't seem right label Jan 28, 2022
@07akioni 07akioni removed the invalid This doesn't seem right label Jan 28, 2022
@tusen-ai tusen-ai deleted a comment from github-actions bot Jan 28, 2022
@07akioni 07akioni reopened this Jan 28, 2022
@robinsimonklein
Copy link

Hi there, any news about this ?
I'm also trying to create a little devtools isolated in a custom element, with vue's defineCustomElement and planning to use Naive UI inside

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

No branches or pull requests

2 participants