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

CssVariables doesn't appear to work with ShadowDOM #43886

Closed
jbrunner92 opened this issue Sep 25, 2024 · 6 comments · Fixed by #43948
Closed

CssVariables doesn't appear to work with ShadowDOM #43886

jbrunner92 opened this issue Sep 25, 2024 · 6 comments · Fixed by #43948
Assignees
Labels
customization: theme Centered around the theming features enhancement This is not a bug, nor a new feature

Comments

@jbrunner92
Copy link

jbrunner92 commented Sep 25, 2024

Steps to reproduce

Link to live example: (https://codesandbox.io/p/sandbox/shadow-dom-forked-s6w62q?workspaceId=2128292f-fbb6-4239-87e8-fa24491716c6)

Steps:

  1. create a theme with cssVariables enabled
  2. Put your ThemeProvider in the shadow DOM.
  3. apply styles

Current behavior

CSS Variables are not being loaded when the ThemeProvider is in the shadow DOM.

image
image

Expected behavior

CSS Variables to be loaded/accessible into the shadow DOM.

image
image

Context

My react application is loaded into an angular application. As such, it is loaded in using the shadow DOM. If I use theme.vars.palette.<some-color> I would expect the css variable for that color to exist. Instead, I have to apply theme.palette.<some-color> if I want the colors to be applied. The problem is I would prefer to use css variables if possible. From what I can tell, MUI should now support shadow DOM - https://mui.com/material-ui/customization/shadow-dom/

Your environment

I am using Google Chrome

npx @mui/envinfo ``` System: OS: macOS 14.7 Binaries: Node: 20.9.0 - ~/.nvm/versions/node/v20.9.0/bin/node npm: 10.5.0 - ~/dev/dlp-configuration/node_modules/.bin/npm pnpm: 9.1.1 - ~/.nvm/versions/node/v20.9.0/bin/pnpm Browsers: Chrome: 129.0.6668.71 Edge: Not Found Safari: 18.0 npmPackages: @emotion/react: 11.13.3 => 11.13.3 @emotion/styled: 11.13.0 => 11.13.0 @mui/core-downloads-tracker: 5.16.7 @mui/icons-material: 6.1.1 => 6.1.1 @mui/material: 6.1.1 @mui/private-theming: 5.16.6 @mui/styled-engine: 5.16.6 @mui/system: 5.16.7 @mui/types: 7.2.17 @mui/utils: 5.16.6 @mui/x-data-grid: 7.18.0 @mui/x-data-grid-pro: 7.18.0 @mui/x-date-pickers: 7.18.0 @mui/x-date-pickers-pro: 7.18.0 @mui/x-internals: 7.18.0 @mui/x-license: 7.18.0 @types/react: 18.2.65 => 18.2.65 react: 18.2.0 => 18.2.0 react-dom: 18.2.0 => 18.2.0 typescript: 5.3.3 => 5.3.3 ```

Search keywords: shadow dom

@jbrunner92 jbrunner92 added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Sep 25, 2024
@Janpot Janpot added the customization: theme Centered around the theming features label Sep 26, 2024
@Janpot
Copy link
Member

Janpot commented Sep 26, 2024

@jbrunner92 the codesandbox link appears to be broken, can you update?

Screenshot 2024-09-26 at 11 54 33

@Janpot Janpot added status: waiting for author Issue with insufficient information and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Sep 26, 2024
@jbrunner92
Copy link
Author

@Janpot I think I fixed the link. Please try again

@github-actions github-actions bot added status: waiting for maintainer These issues haven't been looked at yet by a maintainer and removed status: waiting for author Issue with insufficient information labels Sep 26, 2024
@siriwatknp
Copy link
Member

I almost get it work with https://codesandbox.io/p/sandbox/shadow-dom-forked-h956ms?file=%2Findex.tsx%3A55%2C25.

However, the problem is the CSS variables are generated within :root which does not work with shadow DOM, it has to be configurable to :host.

@siriwatknp siriwatknp added enhancement This is not a bug, nor a new feature and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Oct 1, 2024
Copy link

github-actions bot commented Oct 1, 2024

This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue.
Now, if you have additional information related to this issue or things that could help future readers, feel free to leave a comment.

Note

We value your feedback @jbrunner92! How was your experience with our support team?
We'd love to hear your thoughts in this brief Support Satisfaction survey. Your insights help us improve!

@jbrunner92
Copy link
Author

@siriwatknp thanks for your work on this! Do you know when a new version with those merge changes will be published?

@trungutt
Copy link

trungutt commented Oct 3, 2024

That has been released in 6.1.2 https://github.com/mui/material-ui/releases/tag/v6.1.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customization: theme Centered around the theming features enhancement This is not a bug, nor a new feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants