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.

MuiListItemText-secondary overrides custom theme color for typography variant

See original GitHub issue

When using a <ListItemText/> component with the secondaryTypographyProps set to use a custom variant with a color value, the default color rgba(0, 0, 0, 0.6) overrides the custom variant color.

  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

Setting a custom theme color gets overridden by the default palette.text.secondary.

Expected Behavior 🤔

Setting the color attribute for a custom typography variant should display properly

Steps to Reproduce 🕹

https://codesandbox.io/s/muilistitemtext-bug-6y9k1

image image image

Custom theme…

typography: {
      header3Bold: {
        color: Constants.arrivedDark,
        fontFamily: apercuFonts,
        fontSize: getFontSize(700, isMobile),
        fontWeight: 700,
        lineHeight: '1.133em',
      },
},

Context 🔦

Using a custom typography variant with the color css attribute gets overridden by the default palette.text.secondary.

Your Environment 🌎

`npx @material-ui/envinfo`
System:
    OS: macOS 11.4
  Binaries:
    Node: 15.14.0 - ~/.nvm/versions/node/v15.14.0/bin/node
    Yarn: Not Found
    npm: 7.14.0 - ~/.nvm/versions/node/v15.14.0/bin/npm
  Browsers:
    Chrome: 91.0.4472.114
    Edge: Not Found
    Firefox: Not Found
    Safari: 14.1.1
  npmPackages:
    @emotion/react: ^11.1.5 => 11.1.5
    @emotion/styled: ^11.3.0 => 11.3.0
    @material-ui/codemod: ^5.0.0-alpha.35 => 5.0.0-alpha.35
    @material-ui/core: ^5.0.0-alpha.38 => 5.0.0-alpha.38
    @material-ui/icons: ^5.0.0-alpha.37 => 5.0.0-alpha.37
    @material-ui/lab: ^5.0.0-alpha.38 => 5.0.0-alpha.38
    @material-ui/private-theming:  5.0.0-alpha.36
    @material-ui/styled-engine:  5.0.0-alpha.34
    @material-ui/system:  5.0.0-alpha.38
    @material-ui/types:  6.0.1
    @material-ui/unstyled:  5.0.0-alpha.38
    @material-ui/utils:  5.0.0-alpha.36
    @types/react: ^17.0.2 => 17.0.3
    react: ^17.0.2 => 17.0.2
    react-dom: ^17.0.2 => 17.0.2
    styled-components: ^5.2.1 => 5.2.3
    typescript: ^4.2.3 => 4.2.4

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
siriwatknpcommented, Aug 16, 2021
// ListItemText.js
if (secondary != null && secondary.type !== Typography && !disableTypography) {
    secondary = (
      <Typography
        variant="body2"
        className={classes.secondary}
        color="text.secondary" // <----- turned to `sx` overrides
        display="block"
        {...secondaryTypographyProps}
      >
        {secondary}
      </Typography>
    );
  }

@mnajdova because the color is forced in the ListItemText, that’s why the color from theme (typography variant) is overridden.

0reactions
EliRobinsoncommented, Aug 20, 2021

Ok, I’ll go with a one-off styled solution. I’ll keep following this to see where we land with the order of priority in terms of colors on the secondary text.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Set Typography text color in MUI - reactjs
I would try this - Include a typgraphy property in your theme, something like below with an 'h3' variant ...
Read more >
[theme] Allow custom typography variants · Issue #22257
MUI allows you to add custom keys to the theme configuration. However, there is no way to expand the design system unless you...
Read more >
Theming - Material UI
Customize MUI with your theme. You can change the colors, the typography and much more. The theme specifies the color of the components,...
Read more >
MUI V5: Themes (custom colors + fonts, dark mode ... - YouTube
In this video we go over Material UI V5's Theming! This is a big one, and probably the most important thing to know...
Read more >
Material-UI Typography Tutorial and Examples
The default <Typography> with no props will render a body1 variant, which is just a <p> ... To set a custom color, font-weight...
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