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

Using styled in a Shadow DOM #482

Open
xrofa opened this issue Aug 10, 2022 · 4 comments
Open

Using styled in a Shadow DOM #482

xrofa opened this issue Aug 10, 2022 · 4 comments

Comments

@xrofa
Copy link

xrofa commented Aug 10, 2022

Is there any way of having the styled pre-configured for a specific shadow root so we can use it everywhere importing it directly from 'goober'?
What I'm doing right now is just having:
export const styled = goober.styled.bind({ target: target });

And then importing this styled everywhere in my code.
Is there a better way to define a global target so the styled exported from 'goober' always uses that target?

@cristianbote
Copy link
Owner

Hey there!

Unfortunately there isn't. What I ended-up doing in the past was to re-export everything that needed to be bind to a different target and use the import from there. Not super great but not that bad either. Have you tried that?

@goldmont
Copy link

Hi, same here. News about this? Thanks.

@cristianbote
Copy link
Owner

Hey @goldmont, not much due to limited time availability and lack of support. PRs are welcomed though. I imagine this could be part of the setup function, but not sure if that will cover it.

@fregante
Copy link

fregante commented Jan 19, 2024

this could be part of the setup function

I think that there's no reason to ever use document over the element's shadowRoot when available, so support could/should be automatic.

The only problem is whether goober has access to the react component's DOM element. I think it does in this case:

const Message = styled('div')`
  display: flex;
`;

<Message/>

Internally, it would use div.getRootNode().append(styleElement)

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

4 participants