question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MuiButtonBase-root-MuiMenuItem-root ignores theme override MuiMenuItem (MUI V5.1.0)

See original GitHub issue

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior 😯

I wanted to change the height of my MenuItems globally through a theme override. However, there is another class still overriding the override.

Screenshot 2021-11-16 at 16 12 41

The green arrow is my setting min-height: 4.8rem. The red arrow is the overriding property (MuiButtonBase-root-MuiMenuItem-root min-height).

Expected behavior 🤔

I expect my override (the green arrow) to be the top property, overriding the MuiButtonBase-root-MuiMenuItem-root min-height: auto

Steps to reproduce 🕹

Using plain Select and MenuItem components.

My createTheme:

import { createTheme } from '@mui/material/styles';
import { theme } from './main-theme';

const muiTheme = createTheme({
    palette: {
        primary: {
            main: theme.colors.primary,
            dark: theme.colors.primary,
            light: theme.colors.primary,
        },
    },
    typography: {
        htmlFontSize: 10,
        fontSize: 14,
        fontFamily: ['"Open Sans"', '"sans-serif"'].join(','),
    },
    components: {
        MuiTableCell: {
            styleOverrides: {
                root: {
                    fontSize: '1.6rem',
                },
            },
        },
        MuiMenuItem: {
            styleOverrides: {
                root: {
                    minHeight: '4.8rem', 
                },
            },
        },
        MuiSelect: {
            styleOverrides: {
                root: {
                    fontSize: '1.6rem',
                    width: '100%',
                    backgroundColor: 'var(--color-gray-100)',
                },
                icon: {
                    color: 'var(--color-secondary)',
                },
            },
        },
    },
});

export { muiTheme };

Context 🔦

No response

Your environment 🌎

`npx @mui/envinfo`
Browsers checked: Firefox developer and Safari

System:
    OS: macOS 11.6
  Binaries:
    Node: 14.17.5 - /usr/local/opt/node@14/bin/node
    Yarn: Not Found
    npm: 6.14.14 - /usr/local/opt/node@14/bin/npm
  Browsers:
    Chrome: Not Found
    Edge: Not Found
    Firefox: Not Found [... actually used 95.0b7 (64-bit) Developer Edition ...]
    Safari: 15.0 
  npmPackages:
    @emotion/react: ^11.5.0 => 11.5.0 
    @emotion/styled: ^11.3.0 => 11.3.0 
    @mui/core:  5.0.0-alpha.54 
    @mui/icons-material: ^5.1.0 => 5.1.0 
    @mui/material: ^5.1.0 => 5.1.0 
    @mui/private-theming:  5.1.0 
    @mui/styled-engine:  5.1.0 
    @mui/styled-engine-sc: ^5.1.0 => 5.1.0 
    @mui/styles: ^5.1.0 => 5.1.0 
    @mui/system:  5.1.0 
    @mui/types: ^7.1.0 => 7.1.0 
    @mui/utils:  5.1.0 
    @types/react: ^17.0.11 => 17.0.11 
    react: 17.0.2 => 17.0.2 
    react-dom: 17.0.2 => 17.0.2 
    styled-components: ^5.3.3 => 5.3.3 
    typescript: ~4.3.5 => 4.3.5 

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:2
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ironpfis7commented, May 16, 2022

MuiBaseButton-root styling is getting applied to menu items and switches when I open a mask. It is really bizarre. It is overriding the default styling for those components.

1reaction
TiceWisecommented, Nov 19, 2021

Thanks for your reply. I was able to reproduce the issue in a code box. The codesandbox link: https://codesandbox.io/s/mui-menuitem-height-pi8ft.

At first it looked flaky, sometimes it was working correctly, sometimes it was buggy. I was wondering if it had something to do with the styled-components, so I added that. Then by luck i noticed the screen-width triggered the @media (min-width: 600px) MuiMenuItem-root {min-height: auto}. (So i commented out the styled-component theme to have a minimal example).

One side thing; I noticed the background-color of the select is not changing. What I’m I doing wrong there?

Thanks again!

https://user-images.githubusercontent.com/46386345/142606761-607db0a6-9647-4051-9763-0ed95ae2e93d.mp4

Screenshot 2021-11-19 at 11 14 48
Read more comments on GitHub >

github_iconTop 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 level, so it doesn't leverage the code (which...
Read more >
MenuItem API - Material UI - MUI
Name Type Default autoFocus bool false children node classes object
Read more >
How to customize - Material UI - MUI
From narrowest to broadest use case, here are the options: One-off customization; Reusable component; Global theme overrides; Global CSS override ...
Read more >
Menu API - Material UI - MUI
Name Type Default open * bool false anchorEl HTML element | func autoFocus bool true
Read more >
CSS Baseline - Material UI - MUI
It's using theme.palette.background.default for standard devices and a white ... This API is introduced in @mui/material (v5.1.0) for switching between ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found