Repository navigation
[docs] Fix contrastText description and Button contrast gap - #49928
Merged
Merged
Conversation
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.
Deploy previewBundle size
PerformanceNo 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. |
michelengelen
approved these changes
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The palette docs say
contrastTextis calculated "to maximize the contrast between the background and the text". It isn't:getContrastText()returns white whenever white reachescontrastThresholdand dark text otherwise, without comparing the two. With the default threshold of 3, white is picked on lightwarning(3.11:1, dark would be 6.02:1), lightinfo(3.86:1 vs 4.95:1) and darkerror(3.68:1 vs 5.17:1).palette.md: describe the actual rule. In the Accessibility warning, note thatcontrastTextis computed frommainonly. WithcontrastThreshold: 4.5,infogets dark text, which is 2.68:1 on the hovered contained Button (info.dark).createPalette.js: same correction in the comments.info/warningshortfalls come from thecontrastTextchoice, not the palette. Onlytext/outlinedare bound bymain.Not in scope:
The contrast contract only pins measured ratios. It never checks
contrastTextagainst the rejected alternative, and it covers the light theme only, so darkerrorisn't reported anywhere. Worth a follow-up assertion.Picking the higher-contrast color would change the default
warning/infoand darkerrorbuttons, so it's a breaking change.I have followed (at least) the PR section of the contributing guide.