mui / mui/material-ui

[Typography] Cannot customize primary/error color

Open
#34,290 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

scope: typography type: bug
Dominant language
JavaScript
Stars
99.1k
Forks
32.5k
Avg merge
2d 17h
Merged PRs (30d)
106

Description

Duplicates
  • I have searched the existing issues
Latest version
  • I have tested the latest version
Current behavior 😯

<Typography color="primary"> doesn't allow customizing the color:

  • color="primary" doesn't add any classes that we could use for styling.

  • styleOverrides doesn't support the primary or colorPrimary key:

    styleOverrides: {
      primary: {
        color: palette.primary[palette.mode === "dark" ? "light" : "main"]
      },
    }
    
  • New component variant has no effect:

    variants: [
      {
        props: { color: "primary" },
        style: {
          color: palette.primary[palette.mode === "dark" ? "light" : "main"]
        },
      },
    ],
    
    

Same applies for color="error".

Expected behavior 🤔

Typography provides some way to change the color of color="primary" into palette.primary[palette.mode === "dark" ? "light" : "main"], and same for color="error".

Steps to reproduce 🕹

https://codesandbox.io/s/brave-spence-5wxolh?file=/demo.js

Context 🔦

We're maintaining a UI library based on MUI, so we can't fix this at the <Typography> call site. So we can't do for example <Typography color={palette.primary[palette.mode === "dark" ? "light" : "main"]}>.

Your environment 🌎

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the Typography component and reproduce the behavior from the linked CodeSandbox using color="primary" and color="error". Review how styleOverrides and theme variants are applied to these color props. Done means theme customization changes both colors without requiring changes at each Typography call site.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
design, frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.