components icon indicating copy to clipboard operation
components copied to clipboard

[Bug] MatHint and MatError renders on top of other components.

Open Goodwine opened this issue 9 years ago • 21 comments

Bug, feature request, or proposal:

When MdHint is long enough that it breaks into multiple lines, it ends up rendering on top of other containers.

What is the expected behavior?

2 options:

  1. Push things down. (maybe ugly?)
  2. Use ellipsis but add an md-tooltip or another way to display the rest of the content.

What is the current behavior?

It renders on top of other components and it looks silly.

What are the steps to reproduce?

https://stackblitz.com/edit/angular-dnolru focus and blur any field

What is the use-case or motivation for changing an existing behavior?

We have a "small" error message, something similar to "You need more characters". This is translated on multiple languages and some aren't as short as English so it takes almost double of that. Still, things look ok on a large screen like a PC, but on mobile it renders on top of the components that follow the input.

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

Angular v5.0.0

Goodwine avatar Jun 19 '17 22:06 Goodwine

I can "fix" the issue with some css changes, but ofc it's fragile to future changes.

.mat-input-underline,
.mat-input-subscript-wrapper,
.mat-input-ripple {
  position: initial !important;
  display: block;
}

Goodwine avatar Jun 19 '17 23:06 Goodwine

We should probably address this in the documentation. This is working as intended right now.

You could take two approaches here: either long md-hint and md-error blocks increase the height of the input container or they don't. Right now we intentionally go with "don't" for a couple of reasons:

  • Because the component is display: inline-block, it getting bigger would make things look bad when on the same line as other stuff
  • The idea is that these hints and error messages should be short/concise. If you need to show a significant amount of information, it should be displayed in some other way.

jelbourn avatar Jun 20 '17 01:06 jelbourn

I agree on that it should be short/concise, but not all languages can represent the same message in the same amount of characters. Sure we could find a different way to say the same in a different language so that it's short enough, but this doesn't scale when translations are done by a third party and we translate to a big set of languages. Personally I would go for the option 2 (from the options above) or something similar to that.

Edit: Some random idea (which is probably bad, but trying to do some brainstorming) is doing something like this: https://plnkr.co/edit/g6dwNaVxyjXJSIkkF6bn?p=preview Hover over the error message, the message shown initially with an ellipsis is now expanded.

Goodwine avatar Jun 20 '17 01:06 Goodwine

Don't wan't to throw RTFMs here, but the Material Guidelines states that:

An error message should appear on a single line, if possible.

and for Helper text:

On a single line if possible, or with text wrapping (if multiple lines)

So it explicitly states for helper text (<md-hint>) that it can be multiple lines, and for error messages (<md-error>) it uses words "should, if possible" (for single line), and not "must", so it should also support multiple lines of text. Saying that we should display these texts in some other way if can't fit into single line is against the concepts of material design.

carecki avatar Sep 01 '17 13:09 carecki

Here's an updated plunk of @Goodwine's example https://plnkr.co/edit/QjeolbffC2l7TwOcQcLD?p=preview

willshowell avatar Sep 01 '17 13:09 willshowell

Updated example: https://stackblitz.com/edit/angular-dnolru

@carecki Yes, I agree with your argument, but take the next example as my use case.

<mat-error i18n="Error shown to users when email address is invalid.">
  Please enter a valid email address.
</mat-error>

If you run this example you will see "ok" results, things appear in a single line. image showing form with validation in english

Now, let's say your app has to be translated in multiple languages and you need to support both mobile and desktop. You get the following text provided by your translators (using google translate for the sake of this example):

<mat-error>
  Por favor, introduce una dirección de correo electrónico válida.
</mat-error>

And now things get messed up. Surely I could go ask my translators "please use a very short sentence" but there's eventually going to be a case where such thing is not possible. Angular is just not flexible enough for this. image shows translated example where text looks messed up

Goodwine avatar Dec 22 '17 22:12 Goodwine

@jelbourn It makes sense for material team to want short/concise error messages.

But in general we don't control the length of the text. Especially if error text is internationalized, one line error in English could be multi line error in other languages.

I think it would be cool if material had support for multiline errors. It seems pretty broken: https://stackblitz.com/edit/angular-5njmxc-3x9hm7?file=app/input-overview-example.ts

mertdeg2 avatar May 10 '18 18:05 mertdeg2

I would be open to adding an opt-in option that makes the control grow for multi-line messages. I don't think it should be the default, since I think have a jumping page layout is equally undesirable, but can see how it would be necessary in some situations.

jelbourn avatar May 10 '18 18:05 jelbourn

Any updates on this issue? Best workaround meanwhile?

ianchi avatar Sep 17 '18 20:09 ianchi

@Goodwine you didn't read my comment carefully - by citing material design specs I wanted to show, that specs allows multiline hints, and so should material controls for angular.

@ianchi, for me some custom css rules has been working from angular version 4 I believe. You can test it here: https://stackblitz.com/edit/angular-material2-fix-for-hints-and-errors?file=styles.scss

They css rules, when applied, allow to expand both mat-error and mat-hint. However they don't modify how mat-form-field looks and how much space it occupies when there is no hint or error, or when they take single line. So they are visually backward compatible. The rules are as follows: (I use them globally, in the stackblitz example this is wrapped in custom class, so it affects only right side div).

.mat-form-field {
    .mat-form-field-wrapper {
      padding-bottom: 0;

      .mat-form-field-underline {
        position: initial !important;
        display: block;
        margin-top: -1px;
      }

      .mat-form-field-subscript-wrapper,
      .mat-form-field-ripple {
        position: initial !important;
        display: table;
      }

      .mat-form-field-subscript-wrapper {
        min-height: calc(1em + 1px);
      }
    }
  }

And here how it looks: image

carecki avatar Sep 17 '18 21:09 carecki

Thanks @carecki, I’ll give it a try.

ianchi avatar Sep 19 '18 14:09 ianchi

Does anyone know how to get this working with appearance=outline fields?

jaetea avatar Oct 03 '18 14:10 jaetea

Hi @jelbourn

I undertood that an on growing field may look bad, but we can not design our components like dribble design, that looks amazing on examples but does not work on real life. Like @carecki said, Material's docs allow multi-line hints and erros, so you guys should support this.

Another issue, if you pay attention in @Goodwine images, there is a field with an error message and other field with red label that I can't easy understand when the hint ends and label start because there is no space beetwen input blocks. It is a seriously design (gestalt) issue.

maxandriani avatar Dec 16 '18 17:12 maxandriani

.mat-form-field { .mat-form-field-wrapper { padding-bottom: 0; .mat-form-field-underline { position: initial !important; display: block; margin-top: -1px; } .mat-form-field-subscript-wrapper, .mat-form-field-ripple { position: initial !important; display: table; } .mat-form-field-subscript-wrapper { min-height: calc(1em + 1px); } } }

screenshot 2019-01-09 at 1 41 15 am I have tried with your shared css, does not work. Please see attached screenshot. Thanks.

kamleshwebtech avatar Jan 08 '19 20:01 kamleshwebtech

.mat-form-field { .mat-form-field-wrapper { padding-bottom: 0; .mat-form-field-underline { position: initial !important; display: block; margin-top: -1px; } .mat-form-field-subscript-wrapper, .mat-form-field-ripple { position: initial !important; display: table; } .mat-form-field-subscript-wrapper { min-height: calc(1em + 1px); } } }

screenshot 2019-01-09 at 1 41 15 am I have tried with your shared css, does not work. Please see attached screenshot. Thanks.

try adding :host ::ng-deep

:host ::ng-deep .your-class .mat-form-field {
    .mat-form-field-wrapper {
        padding-bottom: 0;
        .mat-form-field-underline {
            position: initial !important;
            display: block;
            margin-top: -1px;
        }
        .mat-form-field-subscript-wrapper,
        .mat-form-field-ripple {
            position: initial !important;
            display: table;
        }
        .mat-form-field-subscript-wrapper {
            min-height: calc(1em + 1px);
        }
    }
}

karwan5880 avatar Apr 08 '19 03:04 karwan5880

Don't wan't to throw RTFMs here, but the Material Guidelines states that:

An error message should appear on a single line, if possible.

and for Helper text:

On a single line if possible, or with text wrapping (if multiple lines)

So it explicitly states for helper text (<md-hint>) that it can be multiple lines, and for error messages (<md-error>) it uses words "should, if possible" (for single line), and not "must", so it should also support multiple lines of text. Saying that we should display these texts in some other way if can't fit into single line is against the concepts of material design.

Also this becomes even more difficult when accounting for mobile screens that could have significantly narrower displays

ricardosaracino avatar Jun 17 '19 15:06 ricardosaracino

Is anyone in Team working on this issue ? It seems Material has lots of restrictions & doesn't provide that much flexibility to developer .

Kartikkman avatar Feb 02 '20 09:02 Kartikkman

It's your css. https://stackblitz.com/edit/angular-dnolru-y6qxxh?file=styles.css

FARHANE avatar Oct 18 '20 15:10 FARHANE

The new MDC based form field component coming soon in v15 will be able to handle multiple lines for the error message. By default it will be fixed to one line, but there is a new input property on mat-form-field named subscriptSizing that can be set to dynamic to allow for multiple lines.

amysorto avatar Nov 07 '22 23:11 amysorto

@amysorto was this released in version 15 but not in the documentation or did it not make it in?

jakehockey10 avatar Dec 02 '22 03:12 jakehockey10