Custom theme: styleOverrides on Ra* components are not applied
See original GitHub issueWhat you were expecting:
It being possible to override styles of Ra* components in the theme as in v3.
What happened instead:
Styles specified in the theme are not applied. Styles on Mui* components are, however, applied as expected.
Steps to reproduce:
- Create a custom theme and pass it to <Admin>
- Add
styleOverrides
on react-admin components (see below) - Open in browser
Related code:
https://codesandbox.io/s/determined-wilson-k6ifbu?file=/src/index.tsx:722-1068
const theme = _.merge({}, defaultTheme, {
components: {
MuiIconButton: {
styleOverrides: {
root: {
// works as expected
color: "red"
}
}
},
RaList: {
styleOverrides: {
content: {
// does not work
backgroundColor: "red"
}
}
}
}
});
Other information:
Environment
- React-admin version: 4.0.1
- Last version that did not exhibit the issue (if applicable): 3.19.7
- React version: 17.0.2
- Browser: Chrome 100.0.4896.127
- Stack trace (in case of a JS error):
Issue Analytics
- State:
- Created a year ago
- Reactions:2
- Comments:12 (8 by maintainers)
Top Results From Across the Web
Mui v5 styleOverrides not working with themes - Stack Overflow
The issue is that Select doesn't define any styles of its own at the root ... at the theme and applying the corresponding...
Read more >React-admin - Theming
Leveraging this technique, you can create a custom theme that overrides the style of a component for the entire application. For instance, to...
Read more >Themed components - Joy UI - MUI
Learn how to apply custom styles to components at the theme level. ... Use styleOverrides to apply styles to each component slots. Every...
Read more >Overriding styles with the sx prop | Primer React
The sx prop allows ad-hoc styling that is still theme-aware. Declare the styles you want to apply in CamelCase object notation, ...
Read more >When to Use the MUI SX Prop, Styled API, or Theme Override
Do you want to build a full MUI app from beginning to end, learn every aspect of the sx prop, styled API, and...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Well spotted! Would you like to open a PR to fix it?
I haven’t fully understood how MUI wants it now in v5, but from what I understand the
overridesResolver
(for example https://github.com/marmelab/react-admin/blob/master/packages/ra-ui-materialui/src/list/ListView.tsx#L171) would need to be adjusted, see for a somewhat related example: https://mui.com/system/styled/#custom-components.I believe something along these lines should work: