styleoverrides未与MUI中的样式组件一起应用
我正在尝试使用MUI的styleoverrides
将样式应用于使用样式组件构建的组件,但是从另一个软件包中构建的。因此,例如,组件的构建类似于:
const SectionTitle = styled(Box, {
name: 'SectionTitle',
slot: 'Root',
})<WizardSectionTitleProps>(({ width }) => ({
width: width || 'auto',
margin: 0,
}));
在HTML中,该类看起来像:
muibox-root css-d4531u-sectionTitle-root-root
我希望能够使用styleoverrides,例如
const theme = createTheme({
palette: ...,
components: {
SectionTitle: {
styleOverrides: {
root: {
width: '100px',
}
}
}
}
});
:我可以从 mui的全球覆盖物应该工作。另外,我可以将其与MUI组件一起使用,只是我使用stypled-components
构建的自定义零件。该样式未从styleoverrides
中应用。有什么想法吗?
I am trying to use MUI's styleOverrides
to globally apply styles to a component that was built using styled-components, but from another package. So for example, the component is built like:
const SectionTitle = styled(Box, {
name: 'SectionTitle',
slot: 'Root',
})<WizardSectionTitleProps>(({ width }) => ({
width: width || 'auto',
margin: 0,
}));
In the HTML, the class looks like:
MuiBox-root css-d4531u-SectionTitle-root
I want to be able to use styleOverrides, like:
const theme = createTheme({
palette: ...,
components: {
SectionTitle: {
styleOverrides: {
root: {
width: '100px',
}
}
}
}
});
As far as I can tell from MUI's global overrides, this should work. Also I am able to use it with MUI components, just not custom ones I build using styled-components
. The styles are not applied from the styleOverrides
. Any ideas why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
说明:
1. You need to define overrides in the theme, i.e. specify which components will be overridden, example:
2. In addition to defining what will be replaced in the theme, it is also necessary to perform another procedure, which is choose which changes (overrides) that were defined in the theme will be applied, example:
解决方案:
1. Choose in the styled component that all overridden changes in the theme will be applied, example:
2. Apply directly (through
theme
) without having to choose override instyled component
.To do this, you need to define which properties will be passed to the SectionTitle component, as it is a component without properties, just leave it empty, example:
这意味着,如果您使用
&lt; e节标题abc =“ test”/&gt;
您将需要按以下方式定义它:我希望我能有所帮助,任何问题,如果我的答案令人困惑(即使我使用的是Google翻译),请随时评论我可以澄清。
Explanation:
1. You need to define overrides in the theme, i.e. specify which components will be overridden, example:
2. In addition to defining what will be replaced in the theme, it is also necessary to perform another procedure, which is choose which changes (overrides) that were defined in the theme will be applied, example:
Solution(s):
1. Choose in the styled component that all overridden changes in the theme will be applied, example:
2. Apply directly (through
theme
) without having to choose override instyled component
.To do this, you need to define which properties will be passed to the SectionTitle component, as it is a component without properties, just leave it empty, example:
This means that if you use
<Section Title abc="test"/>
you will need to define it as follows:I hope I could have helped, any questions, if my answer is confusing (even because I'm using Google Translate), don't hesitate to comment that I'll be available to clarify.