Skip to content

[docs] Fix contrastText description and Button contrast gap - #49928

Merged
JCQuintas merged 2 commits into
mui:masterfrom
JCQuintas:docs/contrast-text-wording
Nov 27, 2026
Merged

JCQuintas merged 2 commits into
mui:masterfrom
JCQuintas:docs/contrast-text-wording

Conversation

@JCQuintas

Copy link
Copy Markdown
Member

The palette docs say contrastText is calculated "to maximize the contrast between the background and the text". It isn't: getContrastText() returns white whenever white reaches contrastThreshold and dark text otherwise, without comparing the two. With the default threshold of 3, white is picked on light warning (3.11:1, dark would be 6.02:1), light info (3.86:1 vs 4.95:1) and dark error (3.68:1 vs 5.17:1).

  • palette.md: describe the actual rule. In the Accessibility warning, note that contrastText is computed from main only. With contrastThreshold: 4.5, info gets dark text, which is 2.68:1 on the hovered contained Button (info.dark).
  • createPalette.js: same correction in the comments.
  • Button report: the contained info/warning shortfalls come from the contrastText choice, not the palette. Only text/outlined are bound by main.

Not in scope:

  • The contrast contract only pins measured ratios. It never checks contrastText against the rejected alternative, and it covers the light theme only, so dark error isn't reported anywhere. Worth a follow-up assertion.

  • Picking the higher-contrast color would change the default warning/info and dark error buttons, so it's a breaking change.

  • I have followed (at least) the PR section of the contributing guide.

getContrastText() picks white whenever it reaches contrastThreshold and
never compares it with dark text, so the docs claim that it maximizes the
contrast is wrong. Describe the actual rule, note that contrastText is
computed from main only, and correct the Button report: the contained
info and warning shortfalls come from the contrastText choice, not from
the palette.
@JCQuintas JCQuintas added docs Improvements or additions to the documentation. accessibility a11y scope: button Changes related to the button. customization: theme Higher level theming customizability. labels Nov 26, 2026
@JCQuintas JCQuintas self-assigned this Nov 26, 2026
@code-infra-dashboard

code-infra-dashboard Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Deploy preview

Bundle size

Bundle Parsed size Gzip size
@mui/material 0B(0.00%) 0B(0.00%)
@mui/lab 0B(0.00%) 0B(0.00%)
@mui/private-theming 0B(0.00%) 0B(0.00%)
@mui/system 0B(0.00%) 0B(0.00%)
@mui/utils 0B(0.00%) 0B(0.00%)

Details of bundle changes

Performance

No regressions in 32 benchmarks · precise to ±2.2% (±6.0% at worst) · ran 2m 13s · details


Check out the code infra dashboard for more information about this PR.

@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Nov 27, 2026
Master now has the dark-mode error text in the Button 1.4.3 section, from mui#49552. Keep both texts in the gap line and in the section.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Nov 27, 2026
@JCQuintas
JCQuintas merged commit 96b28c5 into mui:master Nov 27, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

accessibility a11y customization: theme Higher level theming customizability. docs Improvements or additions to the documentation. scope: button Changes related to the button.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants