-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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
MuiTextField (v5) not overridden by custom theme when imported from separate package. #29151
Comments
It looks like the same issue as in #29126, which is related to the |
If it is not the same issue, please provide a CodeSandbox, or a link to a repository where we can take a look on the issue. |
It is not the same issue, we are using I will provide a sandbox soon |
I'm getting the same behavior from When I put the styleoverrides into the highest level themeprovider theme, all the styles apply properly. Can't codesandbox atm, because our firewall is blocking the rendering side of condesandbox for some reason. |
Please find the codesandbox here: https://codesandbox.io/s/vigilant-mccarthy-wu823 |
Looks like the popover is affected as well. |
Can you maybe provide a sandbox of how exactly are you nesting the themes? There could be something wrong with that I suppose. It’s unclear from the issue shown in the sandbox that it is not the same bug |
In my case I am only using 1 theme |
Our firewall has been doing weird stuff with the various sandbox sites in the last week, so I'm working on it. Let me ask this though, is the syntax below the correct syntax for There is no example that shows a good theme styleOverride for something like a Popover/Slider that has "slots" (or is a non-trivial component), so the problem might not be related, and might just be PEBKAC. Here's what I've done with my slider and popover in the nested theme, but neither takes hold. However both work when I put them in the outer theme: export const customInnerTheme = createTheme({
components: {
MuiPopover: {
styleOverrides: {
paper: {
opacity: '0.5'
}
}
},
MuiSlider: {
styleOverrides: {
root: {
//styles
}
}
}
}
}) I'll try to get a sandbox repro to you ASAP and we can figure out if this is a bug, user error, or a different issue entirely. |
@bertom I can't tell what is wrong without looking at the code of the component. If it works in the @LongLiveCHIEF the overrides look correct. |
@mnajdova Exactly. The components that come from the package are exactly identical as the ones that are created in the sandbox. (I literally copy-pasted them). Yet some parts, behave differently. |
From debugging the codesandbox seems like the |
we are using |
Can you upgrade to |
@mnajdova I updated the package to |
@mnajdova I have found a similar issue with the |
@bertom taking a look. It's probably similar issue to the |
If I need to guess what is the problem, I would assume this should be the fix: index 6d3bc979e1..328d63b863 100644
--- a/packages/mui-material/src/Box/Box.js
+++ b/packages/mui-material/src/Box/Box.js
@@ -1,14 +1,12 @@
import { createBox } from '@mui/system';
+import styled from '../styles/styled';
import { unstable_ClassNameGenerator as ClassNameGenerator } from '../utils';
-import { createTheme } from '../styles';
-
-const defaultTheme = createTheme();
/**
* @ignore - do not document.
*/
const Box = createBox({
- defaultTheme,
+ styled,
defaultClassName: 'MuiBox-root',
generateClassName: ClassNameGenerator.generate,
});
diff --git a/packages/mui-system/src/createBox.js b/packages/mui-system/src/createBox.js
index 96b04f290d..0620ea83ad 100644
--- a/packages/mui-system/src/createBox.js
+++ b/packages/mui-system/src/createBox.js
@@ -1,16 +1,14 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
-import styled from '@mui/styled-engine';
+import styledEngineStyled from '@mui/styled-engine';
import styleFunctionSx, { extendSxProp } from './styleFunctionSx';
-import useTheme from './useTheme';
export default function createBox(options = {}) {
- const { defaultTheme, defaultClassName = 'MuiBox-root', generateClassName } = options;
+ const { defaultClassName = 'MuiBox-root', generateClassName, styled = styledEngineStyled } = options;
const BoxRoot = styled('div')(styleFunctionSx);
const Box = React.forwardRef(function Box(inProps, ref) {
- const theme = useTheme(defaultTheme);
const { className, component = 'div', ...other } = extendSxProp(inProps);
return (
@@ -21,7 +19,6 @@ export default function createBox(options = {}) {
className,
generateClassName ? generateClassName(defaultClassName) : defaultClassName,
)}
- theme={theme}
{...other}
/>
);
diff --git a/packages/mui-system/src/createBox.test.js b/packages/mui-system/src/createBox.test.js
index 93df9e8ffb..8eaf8b2cc4 100644
--- a/packages/mui-system/src/createBox.test.js
+++ b/packages/mui-system/src/createBox.test.js
@@ -13,13 +13,6 @@ describe('createBox', () => {
expect(container.firstChild).to.have.class('MuiBox-root');
});
- it('should use defaultTheme if provided', () => {
- const Box = createBox({ defaultTheme: { palette: { primary: { main: 'rgb(255, 0, 0)' } } } });
-
- const { container } = render(<Box color="primary.main">Content</Box>);
- expect(container.firstChild).toHaveComputedStyle({ color: 'rgb(255, 0, 0)' });
- });
-
it('should use theme from Context if provided', () => {
const Box = createBox({ defaultTheme: { palette: { primary: { main: 'rgb(255, 0, 0)' } } } }); The problem is that, we already have a test for this inside the @bertom could you help with providing a test. The codesandbox is not helpful as the component used there is hidden behind a private package. |
No, for now I only saw this behavior in the Box component. It looks indeed like this is the issue. |
Current Behavior 😯
We have an app with a custom theme and a
Themeprovider
. Next to that we have a separate package containing components based on MUI components. (All v5)When we import the wrapped
Button
Component from the package, the theme gets applied correctly.When we import the wrapped
Textfield
Component from the package, The theme gets applied partly.When I use the same
TextField
Component form inside the App (not from package, but copied inside the App), The Theme gets applied differently.The component:
The Theme overrides applied correctly:
The Theme overrides applied incorrectly:
These overrides result into this:

The first Component is imported from a package and has custom theme applied to the MuiLabel, but default theme applied to MuiOutlinedInput.
The second component is the same component, but imported locally, it has default theming on the MuiLabel, and custom theme styles applied to MuiOutlinedInput.
Expected Behavior 🤔
Overrides should be the same for all, and also applied in the same way to all 'nested` MUI components (which is the case in MuiTextField). Regardless if the component is imported or not.
Code sandbox
https://codesandbox.io/s/vigilant-mccarthy-wu823
Your Environment 🌎
The text was updated successfully, but these errors were encountered: