In this question I asked how to override a css property of a material-ui component and was provided a nice example. However, when trying to set the height of the Toolbar component I found I could not override the css due to an over arching @media specification. The following MuiTheme spec was my approach:
const theme = createMuiTheme({
overrides: {
MuiToolbar: {
regular: {
height: "32px",
minHeight: "32px"
}
},
}
});
Here is a visual of the css being over-ridden:
If I introduce a hack and add !important to the minHeight it works. A codesandbox showing this is here: https://codesandbox.io/s/4xmr2j2ny9
What is the proper way to overide an @media spec using MuiTheme?
To override the styles of a specific part of the component, use the global classes provided by Material UI, as described in the previous section "Overriding nested component styles" under the sx prop section.
You can however use the classes prop to override a material-ui className. For example <Button classes={{ root: styles. button }} /> . This will remove all material-ui styling though.
If you want to use CSS/SCSS class in MUI component, you should import the file directly in the Table component. But, it's not good to use SCSS with MUI component, you should use makeStyles or withStyles to style the MUI component.
To use the useMediaQuery hook, first import it from Material-UI. import { useMediaQuery } from '@material-ui/core'; In the component, call the useMediaQuery hook and pass in a media query as the argument. This will return a true or false value.
For the record, the latest solution for "@mui/material": "5.0.4",
combined from https://stackoverflow.com/a/52044661/646105 and @jannnik comment, would be:
const defaultTheme = createTheme();
const theme = createTheme({
components: {
MuiToolbar: {
regular: {
backgroundColor: "#ffff00",
color: "#000000",
height: "32px",
minHeight: "32px",
[defaultTheme.breakpoints.up('sm')]: {
minHeight: "48px"
}
},
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With