-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
getColorSchemeSelector returns the wrong selector when multiple are present #43046
Comments
|
This is expected from the styles that you use: <Box
sx={(theme) => ({
height: 100,
width: 100,
backgroundColor: "primary.main",
[theme.getColorSchemeSelector("dark")]: { // << this has higher specificity
backgroundColor: "error.main"
}
})}
/>
To achieve this, I suggest attaching light and dark element in the same level: <div data-mui-color-scheme="light">
…components
</div>
<div data-mui-color-scheme="dark">
…components
</div> |
Thanks for the reply @siriwatknp — I understand what you are saying (and having a bunch of nested containers is probably an edge case that doesn't warrant much effort).
This should work for my particular case, but perhaps not for a more general case where someone needs to nest themes. I think maybe this could be explained better in the documentation. It appears that there is not a way to actually nest themes like there was before with the ThemeProvider. The docs say by using the You can see that in this demo as well (Buttons are styled differently because of the attribute, but both report being in the same mode): https://codesandbox.io/p/sandbox/withered-paper-7dxkzh?file=%2Fsrc%2FDemo.tsx%3A8%2C1&workspaceId=e74d666b-0caf-4132-8ad3-e66da26e8e7e If it's true that you can't actually nest themes, then I think it would help to be more explicit about that in the documentation. |
The issue with the mode can also be seen in MUI components that use Example: https://codesandbox.io/p/sandbox/sharp-waterfall-kx4wtw?file=%2Fsrc%2FDemo.tsx The Breadcrumbs should only be using the grey[100] color if the mode is light, but you can see in the demo it's used for both light and dark containers. https://github.com/mui/material-ui/blob/next/packages/mui-material/src/Breadcrumbs/BreadcrumbCollapsed.js#L15 The Breadcrumbs are just one example, but I've seen a number of other affected components. |
Steps to reproduce
Link to live example: https://codesandbox.io/s/brave-euler-y5ghwt?file=/src/Demo.tsx
Steps:
data-mui-color-scheme
)Current behavior
The dark mode styles are being applied (because there is a dark mode ancestor in the tree) even though the nearest parent element is setting light mode.
Expected behavior
The component should be styled using the light theme rules/values since the nearest parent element specifies light theme.
Context
I'm noticing this in a storybook project where I am trying to show the dark mode styles and light mode styles for a component side by side.
Your environment
npx @mui/envinfo
Using Chrome
Search keywords: CssVars Theme getColorSchemeSelector
The text was updated successfully, but these errors were encountered: