New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Alert] Use getContrastText for filled variant font color #29813
Conversation
@@ -43,6 +43,7 @@ const AlertRoot = styled(Paper, { | |||
})(({ theme, ownerState }) => { | |||
const getColor = theme.palette.mode === 'light' ? darken : lighten; | |||
const getBackgroundColor = theme.palette.mode === 'light' ? lighten : darken; | |||
const getContrastText = theme.palette.mode === 'light' ? lighten : darken; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This returns the same as getBackgroundColor
, so is redundant. It also doesn't do what its name suggests.
We have getContrastText
in the theme. @mnajdova is it also in System? I couldn't find it documented for either theme or system, but I believe it's what @reramjiawan was referring to in the related issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We only have it in the theme.palette
as part of the @mui/material
's theme.
@@ -71,7 +72,10 @@ const AlertRoot = styled(Paper, { | |||
}), | |||
...(color && | |||
ownerState.variant === 'filled' && { | |||
color: '#fff', | |||
color: | |||
theme.palette.mode === 'dark' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This (and line 46) relate to palette mode, but the value of contrast text should presumably depend on the background color being contrasted against, regardless of mode.
The standard variant already has a light background with dark text, so I'm beginning to wonder if the premise of #29731 is faulty, although I suppose it might be the case that user provided colors used in the standard variant are light enough to justify dark text.
@SamoraMabuya Thanks for your first contribution. Can you explain the issue you are trying to fix? |
I was trying to get variant font color to show correct contrast color with getContrastTest method. From what I understand the test contrast is supposed to be dependent on the background color. |
#29731, but see #29813 (comment) (second sentence). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see my comment. I don't think the darken
and lighten
is needed because the color just need to have enough contrast with the background and we have the util in theme.palette.getContrastText
for that.
Co-authored-by: Siriwat K <siriwatkunaporn@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me now 👍
I have made a small update in Alert.js
Changes:
Deploy preview: https://deploy-preview-29813--material-ui.netlify.app/components/alert/
Closes #29731