-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Targeting another emotion component does not work. #1899
Comments
@Andarist I was wondering if it's possible to make the following syntax work: From the examples:const Child = styled.div`
color: red;
`
const Parent = styled.div`
${Child} {
color: green;
}
` That works fine. But what if we need to increase specificity like you can with classNames, by chaining together like Is it possible to implement something like:const Child = styled.div`
color: red;
`
const Parent = styled.div`
${Child}${Child} { // Note the double selector syntax
color: green;
} This seems to work fine as long as the So: const Parent = styled.div`
${({ theme }) => `
${Child}${Child} { // Without css util, works
color: green;
}
`}
`;
const Parent = styled.div`
${({ theme }) => css`
${Child}${Child} { // With css util, explodes
color: green;
}
`}
`; |
@slapbox could you prepare a runnable repro case of your problem? |
@Andarist sure I'd be happy to, but this functionality relies on the Babel plugin being used, right? If so, does that mean I can't create a repro in CodeSandbox, or is there some way to enable the plugin in that environment? |
For the most part, you should be able to use Babel Macros. Just change the import path from |
Oh that's nifty! This should do it, but CodeSandbox is being a bit glitchy for me and sometimes when I load it I'm just getting a blank white screen instead of the error message. |
Ok, I've dropped using Babel Macros there as I hadn't much time to figure out what's wrong. I've prepared an equivalent demo though: https://codesandbox.io/s/emotion-issue-template-forked-odeq5?file=/src/index.js . What Babel plugin does is that it just inserts an option argument with a |
Thanks so much for taking the time to explain that! I'd like to create a full repro, but being honest it's unlikely that I'll be able to find the time before Emotion 11 is finalized since it's only affecting a single line of our entire codebase. The use of I see that the chosen name in Thanks again @Andarist for being one of the greatest people on GitHub! |
The Babel plugin would probably override the manual target - it literally inserts this target to the code, this is how component selectors are implemented. I've just dropped using the Macros because didn't have time to figure out why they didn't work on the codesandbox (and they should). So I've prepared an equivalent demo without a Babel plugin being used - but it contains very similar code to which Babel plugin transpiles styled components. |
Current behavior:
I am following the docs here in order to target another emotion component. Copying the example does not work as no child component styles are applied.
To reproduce:
https://codesandbox.io/s/emotion-issue-template-ll8py?file=/src/index.js
Expected behavior:
The child component should be green but it's red.
Environment information:
react
version: [email protected]emotion
version: [email protected]The text was updated successfully, but these errors were encountered: