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
md error: long error messages overlap input fields #4580
Comments
As stated in the Material Guidelines:
So it should be as short as possible. |
"An error message should appear on a single line, if possible." |
They are positioned absolute, so I don't think it will know where the next input field is. |
Exactly, it looks like I will need to build some workarounds. Would be nice to have the error stretched, otherwise md error seems to be not stable enough considering overlapping. |
a short input field (like zipcode) would almost always have a hint message thats too long, |
What happened with this BUG, I have an input with multiple mat-errors and they are overlapping the rest of the form. is it cause of this Absolutely-Positioned Flex Children . |
This behavior also applies to "Helper text" of form field (
|
And here is my workaround for now (in my // Workaround for https://github.com/angular/material2/issues/4580.
mat-form-field .mat-form-field {
&-underline {
position: relative;
bottom: auto;
}
&-subscript-wrapper {
position: static;
}
} |
It should be noted that this issue is not only for mat-error labels but for mat-hint labels as well. |
perhaps an option to disable inlining errors? The normal behaviour is fine when you've got something like: |
Thanks @xumepadismal faster solution |
I definitely agree with the sentiment that error messages and hint messages "should appear on a single line, if possible". That being said it's not always possible. Especially on mobile. Thanks to @xumepadismal for the css. |
Well basicly error message is defined by browser in js validation api. So I don't understand why material shouldn't support In most cases it won't. |
For 6.0.0 I needed to change @xumepadismal workaround to: mat-form-field .mat-form-field {
&-underline {
position: static;
}
&-subscript-wrapper {
position: static;
}
} If there are problems let me know. |
I love how the response to so many Material issues seems to be "you're doing it wrong". Frankly, I'm really starting to regret having committed to using Material, since it's so narrowly implemented for a very biased way of being used and developers seem to be very dismissive of other views. This is flat out a bug. What if you have multiple validators on a field, and the input triggers more than one? The validations messages will absolutely occupy more than one line, because mat-error will make it so. Hence, ugly overlap is pretty much certain, especially in mobile. |
Is there any reason the solution from @blyndcide / @xumepadismal could not be merged? I'm using it with mat-hints and errors with success. This is very common problem because hints/errors on mobile almost always take more then a single line... Using different hints/errors depending on screen size is |
Any update on this issue ? |
Could you explain me how to use it ? Just copied it in my css file but doesn't not seems to work for me |
@Hydhen For me, the workaround also did not work. I got it working with the following css:
|
You need to nest it in your theme and in your app.module.ts make sure you have something like :::
|
Unless I am missing something, here, no one is mentioning the reason the error fields are marked as absolute in the first place and why changing them to static is not an ideal solution. By default, the form fields have a padding applied to the bottom of them, enough space for the absolute positioned error message to appear in when there is an error. If you change this to static then you introduce arguably a worse problem - whenever an error message appears, any form item underneath the one with an error will suddenly jump down the screen a little because the field with an error now needs more vertical space. With the existing padding + absolute positioning this is not an issue as the form item will always take up a constant amount of vertical space whether an error is shown or not. To my eyes, having fields jumping around when errors appears/disappear is much worse from a UX perspective than worrying about multi-line errors wrapping. You can always increase the default vertical spacing between form elements such that if multiple lines are required, there is space for them to fit into. |
I had the same problem even with a single line of error message, so I created the below solution, which animates in a 13px margin in case a field is touched and invalid. add this to
|
component.css:
In my case, the form-field is a record's code, and the mat-hint is being used to show the descriptive text from the database record for the input code. For us, the record's descriptive text might be too long to fit, but that doesn't matter because the first bit (whatever fits) is enough. |
I agree with these @jimmmeh arguments:
But as I mentioned earlier, even Material Specs allows multiline subscripts if needed. I believe the best approach would be to have min-height reserved for one line of subscript content. Thereby we won't have that "jumping" for short errors/hint while won't overlap them with sibling components. And yes, form fields WILL jump for long errors which is not-so-bad from my point of view. What do you think guys? I modified my workaround and share it on Stackblitz (see styles.scss): |
@xumepadismal solution works great, I would only remove bottom padding in case the control is valid or not touched. This way most of the times elements would not jump
|
This works for me! |
Edited @dJani97's solution little bit:
|
Ith the latest material this works for me
Are there any reasons to not use it like this? |
I had some good results when changing the position attribute to relative on the CSS. It has to be within the ':root' declaration. I put mine in a media query for mobile.
|
For me, this
|
|
For reference, MUI does not have this issue since it doesn't absolutely position the error message, which breaks the flow of the document. I'm not sure why something similar can't be implemented here. Expecting the user to apply custom layout logic to material components is not an adequate solution. |
In Material 15 I believe this is solved in the MDC version of the form fields. You can add You can also make that the default behavior by updating your angular.module.ts providers with the option. |
And this is how to do that:
|
Adding subscriptSizing="dynamic" does not solve the issue for me. |
Adding So for the time being I am sticking to @dJani97's solution. |
Setting Using the solution proposed by @xumepadismal caused error messages to be pushed too much to the bottom, leaving unnecessary empty space at the top. With .mat-mdc-form-field {
@apply w-full self-start;
.mat-mdc-form-field-subscript-wrapper {
@apply flex;
.mat-mdc-form-field-error-wrapper {
@apply static;
}
}
} |
This CSS fixed it for my case: .mat-mdc-form-field-subscript-dynamic-size .mat-mdc-form-field-hint {
margin-bottom: 22px;
} |
Bug, feature request, or proposal:
Bug (or question about) displaying long error messages in md-error
What is the expected behavior?
The error message needs to be visible without overlapping with other input fields
What is the current behavior?
If there are multiple error messages or if a message is too long it is displayed on top of the next input field
What are the steps to reproduce?
The plunk displays an example of a long error message for Last name, which is required, overlapping Email input field and 'Save' button on blur event: http://plnkr.co/edit/LX2iSTxWPJOvNVl0pzy8
What is the use-case or motivation for changing an existing behavior?
Long error messages in input form need to be displayed correctly
Which versions of Angular, Material, OS, TypeScript, browsers are affected?
+-- @angular/animations@4.1.2
+-- @angular/cli@1.0.3
+-- UNMET PEER DEPENDENCY @angular/common@4.1.2
+-- @angular/compiler@4.1.2
+-- @angular/compiler-cli@4.1.2
| +-- @angular/tsc-wrapped@4.1.2
+-- UNMET PEER DEPENDENCY @angular/core@4.1.2
+-- @angular/flex-layout@2.0.0-beta.8
+-- @angular/forms@4.1.2
+-- @angular/http@4.1.2
+-- @angular/material@2.0.0-beta.5
+-- @angular/platform-browser@4.1.2
+-- @angular/platform-browser-dynamic@4.1.2
+-- @angular/router@4.1.2
| +-- @angular/core@2.4.10
| +-- typescript@2.2.2
| `-- typescript@1.8.10
+-- typescript@2.3.2
The text was updated successfully, but these errors were encountered: