You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
All contributors of this release in alphabetical order: @dahiro, @DiegoAndai, @Janpot, @Jtaks, @mj12albert, @oliviertassinari, @sai6855, @siriwatknp, @vipierozan99, @yermartee
Copy file name to clipboardexpand all lines: docs/data/material/migration/upgrade-to-v7/upgrade-to-v7.md
+103-1
Original file line number
Diff line number
Diff line change
@@ -55,7 +55,7 @@ To use the modern bundle (which excludes legacy browser support for smaller bund
55
55
}
56
56
```
57
57
58
-
If you were using a Vite alias to force ESM imports for the icons package, you should remove it as it's no longer necessary:
58
+
If you are using a Vite alias to force ESM imports for the icons package, you should remove it as it's no longer necessary:
59
59
60
60
```diff
61
61
// vite.config.js
@@ -69,6 +69,23 @@ If you were using a Vite alias to force ESM imports for the icons package, you s
69
69
},
70
70
```
71
71
72
+
If you are augmenting the theme and using declarations for nested imports, you should replace them with `@mui/material/styles`. You may also have to rename an interface as some are exported from `@mui/material/styles` under a different name:
The default `data-testid` prop has been removed from the icons in `@mui/icons-material` in production bundles. This change ensures that the `data-testid` prop is only defined where needed, reducing the potential for naming clashes and removing unnecessary properties in production.
162
179
180
+
### Theme behavior changes
181
+
182
+
When CSS theme variables is enabled with built-in light and dark color schemes, the theme no longer changes between modes.
183
+
The snippet below demonstrates this behavior when users toggle the dark mode, the `mode` state from `useColorScheme` changes, but the theme object no longer changes:
184
+
185
+
```js
186
+
import {
187
+
ThemeProvider,
188
+
createTheme,
189
+
useTheme,
190
+
useColorScheme,
191
+
} from'@mui/material/styles';
192
+
193
+
consttheme=createTheme({
194
+
cssVariables: {
195
+
colorSchemeSelector:'class',
196
+
},
197
+
colorSchemes: {
198
+
light:true,
199
+
dark:true,
200
+
},
201
+
});
202
+
console.log(theme.palette.mode); // 'light' is the default mode
203
+
204
+
functionColorModeToggle() {
205
+
const { setMode, mode } =useColorScheme();
206
+
consttheme=useTheme();
207
+
208
+
React.useEffect(() => {
209
+
console.log(mode); // logged 'light' at first render, and 'dark' after the button click
210
+
}, [mode]);
211
+
212
+
React.useEffect(() => {
213
+
console.log(theme.palette.mode); // logged 'light' at first render, no log after the button click
214
+
}, [theme]);
215
+
216
+
return<button onClick={() =>setMode('dark')}>Toggle dark mode</button>;
217
+
}
218
+
219
+
functionApp() {
220
+
return (
221
+
<ThemeProvider theme={theme}>
222
+
<ColorModeToggle />
223
+
</ThemeProvider>
224
+
);
225
+
}
226
+
```
227
+
228
+
This default behavior was made to improve performance by avoiding unnecessary re-renders when the mode changes.
229
+
230
+
It's recommended to use the `theme.vars.*` as values in your styles to refer to the CSS variables directly:
231
+
232
+
```js
233
+
constCustom=styled('div')(({ theme }) => ({
234
+
color:theme.vars.palette.text.primary,
235
+
background:theme.vars.palette.primary.main,
236
+
}));
237
+
```
238
+
239
+
If you need to do runtime calculations, we recommend using CSS instead of JavaScript whenever possible.
240
+
For example, adjusting the alpha channel of a color can be done using the [`color-mix` function](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/color-mix):
However, if CSS approach is not possible, you can access the value directly from the `theme.colorSchemes` object, then apply both light and dark styles:
If any of the methods above do not suit your project, you can opt out from this behavior by passing the `forceThemeRerender` prop to the ThemeProvider component:
260
+
261
+
```js
262
+
<ThemeProvider forceThemeRerender />
263
+
```
264
+
163
265
### Deprecated APIs removed
164
266
165
267
APIs that were deprecated in v5 have been removed in v7.
0 commit comments