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

[system] theme.getColorSchemeSelector is not a function #40178

Closed
Tracked by #40225
mtr1990 opened this issue Dec 11, 2023 · 2 comments · Fixed by #41446
Closed
Tracked by #40225

[system] theme.getColorSchemeSelector is not a function #40178

mtr1990 opened this issue Dec 11, 2023 · 2 comments · Fixed by #41446
Assignees
Labels
customization: theme Centered around the theming features enhancement This is not a bug, nor a new feature package: system Specific to @mui/system

Comments

@mtr1990
Copy link

mtr1990 commented Dec 11, 2023

Steps to reproduce 🕹

theme.getColorSchemeSelector("light") or theme.getColorSchemeSelector("dark")

image

https://codesandbox.io/p/sandbox/gracious-babbage-d8xdpy?file=%2Fsrc%2FDemo.tsx%3A27%2C21-27%2C59

Current behavior 😯

theme.getColorSchemeSelector("light") Doesn't work at root level

but work at a lower level

const theme = useTheme()
theme.getColorSchemeSelector("light") => Work

Expected behavior 🤔

Works at root level like MUI JOY :

https://codesandbox.io/p/sandbox/cool-sun-j6wjvf?file=%2Fsrc%2FDemo.js%3A110%2C71

Context 🔦

No response

Your environment 🌎

No response

@mtr1990 mtr1990 added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Dec 11, 2023
@zannager zannager added package: system Specific to @mui/system customization: theme Centered around the theming features labels Dec 11, 2023
@siriwatknp
Copy link
Member

This is because getColorSchemeSelector is appended by CssVarsProvider because the function needs attribute from CssVarsProvider's props.

I think we can improve this by delegating the attribute to the extendTheme and set getColorSchemeSelector to the theme. With this, zero-runtime can read and use the attribute internally cc @brijeshb42

@siriwatknp siriwatknp added the enhancement This is not a bug, nor a new feature label Dec 13, 2023
@mtr1990
Copy link
Author

mtr1990 commented Dec 14, 2023

Thank you for providing feedback.

If we can deliver in extendTheme instead of under CssVarsProvider then customization will be better

Currently I can temporarily rewrite the getColorSchemeSelector function for use:

export function getMode(mode) {
  if (mode === 'light') {
    return `[data-mui-color-scheme="light"] &`;
  }
  return `[data-mui-color-scheme="dark"] &`;
}

But I realized other functions like pallet also don't work inside extendTheme like Mui Joy.

My need is to customize the theme before creating in <CssVarsProvider theme={theme}>

So I need properties like mode (console.log("palette", theme.palette.mode);)

There is also solution for this using global state. But then const { mode, setMode } = useColorScheme(); will lose its meaning and we have to write some extra code to further handle the mode state, which is not necessary

image

Hopefully this will improve.

@mapache-salvaje mapache-salvaje removed the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Dec 15, 2023
@danilo-leal danilo-leal changed the title theme.getColorSchemeSelector is not a function [system] theme.getColorSchemeSelector is not a function Dec 25, 2023
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 package: system Specific to @mui/system
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants