Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding ErrorText to material-ui Textfield moves other elements

I have a signup form in a React app. I am using material-ui TextField and use the errorText property to add a message if there is an error in the input.

errorText={this.state.messages.emailMessage}

The state.messages.emailMessage is initially set to null and so TextField does not have the extra space for the message when the input is first rendered.

When the message is added it moves the other elements.

How can I allow space for the new node if it is needed so that the other elements are not moved? I tried setting the initial state of the message to ' ' but this colours the input red for error and doesn't work anyway!

like image 338
leonormes Avatar asked Jun 07 '26 03:06

leonormes


2 Answers

You can make them a fixed height by making the helperText equal to an empty space when there is no message to show.

<TextField helperText={error ? error.message : ' '} />
like image 51
Christopher Caldwell Avatar answered Jun 08 '26 16:06

Christopher Caldwell


You could just use the errorStyle property setting an absolute position.. That's how I fix those problems in my projects.

like image 39
André Junges Avatar answered Jun 08 '26 16:06

André Junges