question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[TextField] When changing font size, the text is not aligned.

See original GitHub issue
  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Similiar Issues:

https://github.com/mui-org/material-ui/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:

const theme = createMuiTheme({
  typography: {
    fontFamily: 'Averta',
    fontWeightRegular: 500,
  },
 overrides: {
    MuiTextField: {
      root: {
        fontSize: '20px'
      },
    },
    MuiInputLabel: {
      shrink: {
        fontSize: '20px',
      },
      root: {
        fontSize: '20px',
      },
}
});

an example of such text field would look like: image

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:

image

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 🌎

Tech Version
Material-UI v4.9.5
React 16.13.0
Browser chrome-latest
TypeScript 3.8.3

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
oliviertassinaricommented, Mar 4, 2020

@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)"
      }
    }
  }
});

https://codesandbox.io/s/lingering-haze-hnop1

1reaction
OriginLivecommented, Mar 4, 2020

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[TextField] When changing font size, the text is not aligned.
When overriding font size, the text does not align correctly. Expected Behavior 🤔. Text should be in the center, there should be a...
Read more >
Cannot change font size of text field in material ui
The most straight forward way to change the font size of both the input label and the input text is to use inline...
Read more >
Align text in textfield and change font size | Adobe Acrobat
Hi, I have multiline textfield and tried to align my text using javascript onlick event of a button. TextField1_1.alignment = "justify";
Read more >
Align text or adjust the margins within a text box
In a text box in Word, you can align text horizontally or vertically, and you can adjust the margins to be narrower or...
Read more >
Respect Text Alignment when changing font size | Miro
Before pressing the font size up or down arrow Pressing the font size up button once - the text field is still right...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found