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] helperText fixed height

See original GitHub issue

Problem description

I’m a bit confused as to how have a proper error text in a form using TextField (think 'Both password should match").

I tried different approach:

  • display the error text in label when there is an error
    • you don’t have a label anymore, it’s a bit confusing
  • display the error text in helperText
    • the height change depending if there is an error or not. It’s not great to have clean layout and the form start to move around with each error.
    • setting helperText to an empty string doesn’t fix the height issue.
  • force helperText to be a FormHelperText with an error string or not
    • even if it’s not a string, TextField will still wrap it in another FormHelperText which lead to a <p> inside a <p> and a complain by react. This is not the behavior expected when you read the documentation.
  • change the margin property
    • none of them gives a stable height in this case.

Any hint ?

Versions

  • Material-UI: 1.0.0-beta.4

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
MichaelMurecommented, Aug 13, 2017

Ho, actually, using a space for helperText is working. I got confused somehow.

sans titre

For the next guy, I’m using this finally (for redux-form):

export const renderTextField = ({ input, meta: { touched, error }, ...custom }) => (
  <TextField
    error={touched && (error != null)}
    helperText={(touched && (error != null)) ? error : ' '}
    {...input}
    {...custom}
  />
)

So it’s working, but it still feel a bit awkward to me. Anyway …

0reactions
mizanmahicommented, Feb 26, 2022

In my project I fixed it in this way, blank space is the hack here

<SolrufTextFieldGray
   size='small'
   conText={<InsertLinkIcon />}
    label='Video Intro'
    style={{ marginBottom: '1rem' }}
    {...register('video_url', {
        required: {
            value: true,
             message: 'Video is Required',
        },
    })}
  error={errors.video_url}
  helperText={
    errors.video_url ? errors.video_url.message : ' '
  }
   />
Read more comments on GitHub >

github_iconTop Results From Across the Web

Text field with helper text should be the same height as without
I render " " to render empty helper text so the height of the input is always the same and the rest doesn't...
Read more >
How to set the height knowing that under input will helper text ...
Rudolf's answer is close to what you need, but the minHeight needs to be applied to the TextField ( FormControl if using lower-level ......
Read more >
fix height of TextField material Ui Code Example - Code Grepper
Queries related to “fix height of TextField material Ui” ... material ui textfield helper text size · text field material ui dimensions ·...
Read more >
React Text Field component - Material UI - MUI
The multiline prop transforms the text field into a TextareaAutosize element. Unless the rows prop is set, the height of the text field...
Read more >
How to Set MUI TextField Height and Width: The 3 Best Ways
Set MUI Height and Width with 'sx' Prop ... Perhaps the simplest way to set TextField width and height is to use only...
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