-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
[Typography] Better defaults #15100
[Typography] Better defaults #15100
Conversation
Details of bundle changes.Comparing: 264c64d...d6bed5e
|
a5a4adb
to
8c9adf4
Compare
b3dd7a9
to
35843c5
Compare
35843c5
to
9febe8a
Compare
Hey thanks for improving this @oliviertassinari! I was tagged in an email notification that originally included comments referencing the changes I proposed for |
It’s hard to see in Argos what each of the changes affected. I can have a look later, they all sound like good changes 👍 |
@ianschmitz I have looked at it yes. I have reverted the change. The textfield already mounts a lot of components, it would add one more to the equation. I couldn't see any direct gain. I will try to apply theme.typography.x variant. But more importantly, I focus on the breaking changes here. Anything that can be handled later, should be handled later. |
@joshwooding Argos has been incredibly useful for this pull request. I have tried to fix all the abnormal changes. I might have missed a few. If you could review it, it would be awesome. We can wait tomorrow to merge the changes. It the least we can do for important breaking changes like those. |
@oliviertassinari Looking at it now it looks fine, the reason I didn’t earlier is because I was on a phone. |
@joshwooding Thanks for double checking, we can change the solution up until v4 stable is released. |
@oliviertassinari Shouldn't the text color also reflects on the ThemeProvider? i mean, on the dark theme the text color is dark https://codesandbox.io/s/4w8z5mlox |
@cesardeazevedo Yes, you have two options. You can:
|
Thanks so much @oliviertassinari, the impact that i see with this change is when adding nesting themes, as you can see here https://codesandbox.io/s/43q4y70nr7 Of course could be easily fixed with the prop |
Thanks for providing more details. Yes, you are right. The color inheritance change makes theme nesting a bit harder. |
@@ -32,7 +32,7 @@ export default function createTypography(palette, typography) { | |||
const coef = fontSize / 14; | |||
const pxToRem = size => `${(size / htmlFontSize) * coef}rem`; | |||
const buildVariant = (fontWeight, size, lineHeight, letterSpacing, casing) => ({ | |||
color: palette.text.primary, | |||
// color: palette.text.primary, |
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.
I think this has potentially caused problems with dark mode. Is the expectation that the default variant (initial) does not change colour when in a dark theme? Or should we explicitly request textPrimary for this to work?
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.
@adamscybot A top-level CssBaseline component can change it or a <Typography component="div color="textPrimary" />
.
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.
@oliviertassinari So I think the main issue is that some components like ListItem do not use the typography "textPrimary" colour, and so out of the box "dark mode" type does not change these components which is a bit unexpected. I made a code sandbox of what I mean here: https://codesandbox.io/s/8qmjywo80.
I can add wrappers/theme overrides to provide the right colour downwards, but it seems like an unexpected default. Or perhaps a documentation change is needed.
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.
Thank you for the reproduction. What do you think of adding the color property to the ListItem's Typography component?
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.
Yeh that would work. I guess what we're basically saying is that if its used internally to MUI rather than directly in userland, it should use textPrimary
? Are there other places its needed? To be honest, I hadn't considered that this could actually just be a props configuration issue for ListItem that's come about because of this change. I don't know if dark mode is acting differently elsewhere.
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.
I'm wondering if it shouldn't be the Paper responsibility to set the color in conjunction with the background color.
--- a/packages/material-ui/src/Paper/Paper.js
+++ b/packages/material-ui/src/Paper/Paper.js
@@ -16,6 +16,7 @@ export const styles = theme => {
/* Styles applied to the root element. */
root: {
backgroundColor: theme.palette.background.paper,
+ color: theme.palette.text.primary,
},
/* Styles applied to the root element if `square={false}`. */
rounded: {
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.
Giving color to Paper element is seems to me a valid solution. Like body element we are giving base color for children inheritance. This also solves the issue for body appended components like dialog, menu which are using paper.
This is another reproduction with some components and nested theming:
https://codesandbox.io/embed/32mxj2o9wm
I gave color and bg to the themes content (thinking as a body of the nested theme)
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.
@mustafahlvc do you want to submit a pull request with the above fix? :)
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.
Of course #15465
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.
Awesome thanks a lot guys, I think this solution makes sense.
An FYI, 4.0.2, adding CssBaseline/ only went so far. Many things were modified, but 2 were not. MuiButtonBase and MuiSnackbarContent both still had the darker foreground color (color: inherit), necessitating overrides in my Theme Creator. Buttons being dark text was inconsistent. Some were just fine, but button for the ListItem component were always dark. When I can, I'll go back to the above code snippets and see if I can replicate outside of my app. (note, neither of those are directly inside Typography components) UPDATE: It wasn't made clear that CssBaseline needs to be INSIDE the Theme Provider component. Previously, it would exist outside with no issues. That resolved the MuiButtonBase problem, though MuiSnackbarContent is still picking the darker color. |
Breaking changes
These are the last changes for the typography I'm proposing for stable v4:
body2
tobody1
. 16px is a better default than 14px. Bootstrap, material.io or even our documentation use 16px as a default font size. 14px like Ant Design is understandable as Chinese users have a different alphabet. We document 12px as the default font size for Japanese.color="default"
tocolor="initial"
following the logic of [RFC] color prop API #13028. The usage of default should be avoided. cc @eps1lon