-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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
[TextField] When changing font size, the text is not aligned. #19952
Comments
@OriginLive Did you try to customize the transition? I don't think that we have any leverage to improve this problem. It requires to compute the right CSS transition x and y values. |
@oliviertassinari could you give an example of how to override a label transition and how to center it correctly? Here's an example in codesandbox: |
@OriginLive Definitely! Here we go: const theme = createMuiTheme({
typography: {
fontFamily: "Averta",
fontWeightRegular: 500
},
overrides: {
MuiOutlinedInput: {
root: {
fontSize: "20px"
},
input: {
padding: "16px 14px",
height: 56,
boxSizing: "border-box"
}
},
MuiInputLabel: {
root: {
fontSize: "20px"
},
outlined: {
transform: "translate(14px, 19px) scale(1)"
}
}
}
}); |
@oliviertassinari |
@OriginLive Ok, updated |
@oliviertassinari could you please explain how you got the 19px in "translate(14px, 19px) scale(1)" for future reference please. And the padding size. |
19px is limited to the fact that it feels right. In #8017, I think that we come to the conclusion that we can't easily write CSS that displays great value for any potential configurations. |
I assume padding is the same? Damn, it would be nice to have that calculated somewhere. |
The padding value is less important, I couldn't get a "round" line-height value based on the font and font-size so I went with something that would be a bit below 56px, and set it with an explicit height CSS property. |
@oliviertassinari just to let you know, there's also a way to use: MuiInputBase: {
root: {
fontSize: '20px',
lineHeight: '23px',
},
input: {
height: '0.95em',
}
}, instead of MuiOutlinedInput: {
input: {
padding: "16px 14px",
height: 56,
boxSizing: "border-box"
}
}, part. The em part scales better i believe. Not quite sure how it affects everything else, but i feel like border-box with height seems a bit hackish. |
Similiar Issues:
#8017
Current Behavior 😯
When overriding font size, the text does not align correctly.
Expected Behavior 🤔
Text should be in the center, there should be a prop accepting font size. Currently, it's using transformation to move the label upwards on click. The coordinates do not account for different font size.
Steps to Reproduce 🕹
Here's my following code:
an example of such text field would look like:

As you can see, the text isn't aligned, it's meant to be aligned at 12px. To exaggerate the problem, look at the following:
It's even more obvious with larger fonts.
Context 🔦
I'm trying to change the height of the textfield component so that it matches our figma height and it's font-size (56px in height) and 20px font size. I assume it's also a problem to align with just using inputbase and outlined input.
Your Environment 🌎
The text was updated successfully, but these errors were encountered: