-
-
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
Don't add classname for :is()
and :where()
selectors
#2836
Comments
This is a byproduct of our Right now you sort of can achieve this by combining |
@Andarist Thanks a lot for the info.
Can you point me to where to fix this? I can submit a PR. Note, from what I check |
My guess is that the problem is in this
But I didn't yet analyze this in full. One alternative solution that I was thinking about (since adding the |
I can think of:
The usage would look like this, right? const Component = style('div')`
color: black
~:where([data-color-scheme="dark"]) & {
color: white
}
` |
I found a workaround! https://codesandbox.io/s/emotion-forked-6eco3g?file=/index.js |
Note that this might be prone to some edge cases but it probably shouldn't matter for real-life cases in which you are gonna use this. |
After thinking about this a little bit - I think that a comment annotation would be the easiest solution for this. Something like: const Component = style('div')`
color: black
:where([data-color-scheme="dark"]) & {
/* emotion-no-compat */
color: white
}
` I think I'm gonna add a dev-only warning for all instances of the "compat" behavior kicking in so people can start fixing their selectors in v11 but I can't change this default right now. Note that whatever we could do about this in Emotion right now would require a new v11 minor version - and, from what I understand, you need this in MUI and you don't control which version of Emotion people have installed there as its a peer dep. So I'm unsure if any solution from our side would actually solve your issue - unless you expect people to update Emotion frequently. |
We have a util function that produces styled('div')(({ theme }) => ({
// theme.getColorSchemeSelector('dark') => ':where([data-color-scheme="dark"]) &'
[theme.getColorSchemeSelector('dark')]: {
/* emotion-no-compat */
// ...styles
}
})) |
It may not work for all use-cases, but in case anyone else comes looking, I've had success with using the
const texStyle = css`
color: red;
* :where([data-your-theme-value="example"]) & {
color: blue;
}
`
() => (
<>
<div data-your-theme-value='example'>
<span css={textStyle}> Blue Text Here </span>
</div>
<span css={textStyle}>Red Text Here</span>
</>
) See the codesandbox PoC here |
Oh, great. Thanks for letting me know. |
Unfortunately, this solution breaks down completely when using Emotion object notation. <div
css={{
color: 'black',
':where([data-color-scheme="dark"]) &': {
/* emotion-no-compat */ // <== this is just a JS comment; will not be interpreted by Emotion.
color: 'white',
}
}}
> |
Was this ever resolved? |
Solved in #3210 |
The problem
I want to leverage
:where
selector (it is good for theming because it has 0 specificity) to style a component based on the parent attribute.However, emotion prefix the style with the generated class name in front of
:where
which does not make the style works:turned into
Here is the reproduction: https://codesandbox.io/s/emotion-forked-e9fyes?file=/index.js
Proposed solution
Should
:is
and:where
be the exceptional case to not implicitly append to the class name?Alternative solutions
Is there any workaround that I might have missed?
Additional context
Hi, I am from the MUI core team. We are working on the theming API to let developers theme components based on color schemes without having to read the mode from the theme.
Our API added an attribute to the html when the color scheme changes:
The text was updated successfully, but these errors were encountered: