Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

ngMessages UI jump when used in combo with ng-show #5298

Closed
houmark opened this issue Oct 21, 2015 · 12 comments
Closed

ngMessages UI jump when used in combo with ng-show #5298

houmark opened this issue Oct 21, 2015 · 12 comments

Comments

@houmark
Copy link

houmark commented Oct 21, 2015

Sometimes it's nice to only show an error message after a field is touched or submitted. So to do that we have used ng-show on the outer ng-messages element like below:

<div ng-messages="ctrl.form.title.$error" ng-show="ctrl.form.title.$touched || ctrl.form.$submitted" role="alert">

This works fine, but since some of the recent changes related to "multiple" we started seeing a small "UI jump" when leaving the field and the error message was to be shown (or not due to no errors).

To reproduce:

Add the ng-show condition on a field with ng-messages, focus the field, leave the field. The design will now jump just one pixel or so (only the first time).

Not exactly sure what would be the simplest solution, but I thought I would at least report this so someone else might be able to figure out a simple solution.

@peio72
Copy link

peio72 commented Oct 21, 2015

+1

@chrislambe
Copy link

Also being affected by this.

Edit: I think I jumped the gun on the cause. It seems a little more complicated than that one rule. Still digging into it.

Edit 2: This is a deeper rabbit hole than I expected. Gotta bail, sorry!

@ngraef
Copy link
Contributor

ngraef commented Oct 30, 2015

@houmark Is your issue fixed by faa8b5b?

@houmark
Copy link
Author

houmark commented Oct 31, 2015

With the specific bottom border yes, but I have another somehow related issue now which makes a larger jump in the area below the the input field only when I have a condition on the ng-messages, which creates a ~24px height below due to the ng-messages first being display:none; due to ng-hide and that changes after the first validation (when blurring the field) — even if the validation is successful.

So it's a part fix for me or something else not directly related to this one but related to ng-messages and recent changes.

I've checked if we have anything special going on in our styling, but it does not look like it, it's pretty basic, but the combo with the ng-show on the ng-messages seems to be the reason for this.

@houmark
Copy link
Author

houmark commented Oct 31, 2015

I created a simple pen (forked from the input demo) where I added the ng-show on the "first name" field and one error message. As you can see, there's a whole lot of jumping going on there. Didn't use to be like that and I find this to be largely disturbing to a smooth UI.

Pen here: http://codepen.io/houmark/pen/zvaWyb/

Also the postal code is jumping around when erroring, but I did not touch that one at all and it acts the same in the demo.

@ngraef
Copy link
Contributor

ngraef commented Oct 31, 2015

The sliding up and down in your demo is fixed on master (by the commit mentioned above). Demo: http://codepen.io/anon/pen/GpGYeb

So as you mentioned, the issue is that md-input-container doesn't allocate space for ng-messages, so the UI jumps when ng-messages is shown after initially being hidden.

This snippet of CSS fixes the issue, but it's very much a workaround, not a solution:

md-input-container [ng-messages].ng-hide {
    display: block !important;
    visibility: hidden;
}

@houmark
Copy link
Author

houmark commented Nov 2, 2015

@ngraef Yeah, I had been brewing on something similar, and while it's a workaround, it's not really that bad and has made our forms stable again (read non-jumpy), so thanks for that. Hope to see a more permanent fix soonish :)

@topherfangio topherfangio modified the milestones: 1.0-rc4, 1.0-rc3 Nov 2, 2015
@oste
Copy link
Contributor

oste commented Nov 6, 2015

here is a demo showing the issue http://codepen.io/oste/pen/ZbMVLj

It should be noted that updating this code to RC2 causes the message to jump around even more. I can't provide a demo b/c RC2 is not available via CDN.

@mallowigi
Copy link
Contributor

+1

@maelfrize
Copy link

+1

@satheesh786
Copy link

same issue @houmark

@sunny9240
Copy link

+1

@ThomasBurleson ThomasBurleson modified the milestones: 1.0-rc4, 1.0-rc5 Nov 16, 2015
@topherfangio topherfangio added the in progress Mainly for in progress PRs, but may be used for issues that require multiple PRs label Nov 19, 2015
@ThomasBurleson ThomasBurleson modified the milestones: 1.0-rc5, 1.0-rc6 Nov 25, 2015
@ThomasBurleson ThomasBurleson modified the milestones: 1.0-rc6, 1.0-rc7 Dec 3, 2015
topherfangio added a commit that referenced this issue Dec 8, 2015
When the ngMessages directive was used with the ngShow,
ngIf and other directives inside of an md-input-container,
the messages would flicker and jump rather than properly
animating.

Additionally, if the messages spanned multiple lines,
the animations were incorrect due to hard-coded values.

Fix many styles and move animations into JS so we can
properly calculate message heights.

Also, add more flexibility with the `md-auto-hide` CSS
class and associated attribute and update docs/demo
accordingly.

BREAKING CHANGE

By default, the `<md-input-container>` now automatically
hides any error messages until the component is in an
error state (determined by `md-is-error`). If you wish
to achieve the original behavior where messages are
always visible, add the `md-auto-hide="false"` attribute
to your `ng-messages` or use one of the following
visibility directives:

 - `ng-if`
 - `ng-show`/`ng-hide`
 - `ng-switch-when`/`ng-switch-default`

Fixes #5298.
topherfangio added a commit that referenced this issue Dec 8, 2015
When the ngMessages directive was used with the ngShow,
ngIf and other directives inside of an md-input-container,
the messages would flicker and jump rather than properly
animating.

Additionally, if the messages spanned multiple lines,
the animations were incorrect due to hard-coded values.

Fix many styles and move animations into JS so we can
properly calculate message heights.

Also, add more flexibility with the `md-auto-hide` CSS
class and associated attribute and update docs/demo
accordingly.

BREAKING CHANGE

By default, the `<md-input-container>` now automatically
hides any error messages until the component is in an
error state (determined by `md-is-error`). If you wish
to achieve the original behavior where messages are
always visible, add the `md-auto-hide="false"` attribute
to your `ng-messages` or use one of the following
visibility directives:

 - `ng-if`
 - `ng-show`/`ng-hide`
 - `ng-switch-when`/`ng-switch-default`

Fixes #5298.
topherfangio added a commit that referenced this issue Dec 8, 2015
When the ngMessages directive was used with the ngShow,
ngIf and other directives inside of an md-input-container,
the messages would flicker and jump rather than properly
animating.

Additionally, if the messages spanned multiple lines,
the animations were incorrect due to hard-coded values.

Fix many styles and move animations into JS so we can
properly calculate message heights.

Also, add more flexibility with the `md-auto-hide` CSS
class and associated attribute and update docs/demo
accordingly.

BREAKING CHANGE

By default, the `<md-input-container>` now automatically
hides any error messages until the component is in an
error state (determined by `md-is-error`). If you wish
to achieve the original behavior where messages are
always visible, add the `md-auto-hide="false"` attribute
to your `ng-messages` or use one of the following
visibility directives:

 - `ng-if`
 - `ng-show`/`ng-hide`
 - `ng-switch-when`/`ng-switch-default`

Fixes #5298.
topherfangio added a commit that referenced this issue Dec 8, 2015
When the ngMessages directive was used with the ngShow,
ngIf and other directives inside of an md-input-container,
the messages would flicker and jump rather than properly
animating.

Additionally, if the messages spanned multiple lines,
the animations were incorrect due to hard-coded values.

Fix many styles and move animations into JS so we can
properly calculate message heights.

Also, add more flexibility with the `md-auto-hide` CSS
class and associated attribute and update docs/demo
accordingly.

BREAKING CHANGE

By default, the `<md-input-container>` now automatically
hides any error messages until the component is in an
error state (determined by `md-is-error`). If you wish
to achieve the original behavior where messages are
always visible, add the `md-auto-hide="false"` attribute
to your `ng-messages` or use one of the following
visibility directives:

 - `ng-if`
 - `ng-show`/`ng-hide`
 - `ng-switch-when`/`ng-switch-default`

Fixes #5298.
topherfangio added a commit that referenced this issue Dec 8, 2015
When the ngMessages directive was used with the ngShow,
ngIf and other directives inside of an md-input-container,
the messages would flicker and jump rather than properly
animating.

Additionally, if the messages spanned multiple lines,
the animations were incorrect due to hard-coded values.

Fix many styles and move animations into JS so we can
properly calculate message heights.

Also, add more flexibility with the `md-auto-hide` CSS
class and associated attribute and update docs/demo
accordingly.

BREAKING CHANGE

By default, the `<md-input-container>` now automatically
hides any error messages until the component is in an
error state (determined by `md-is-error`). If you wish
to achieve the original behavior where messages are
always visible, add the `md-auto-hide="false"` attribute
to your `ng-messages` or use one of the following
visibility directives:

 - `ng-if`
 - `ng-show`/`ng-hide`
 - `ng-switch-when`/`ng-switch-default`

Fixes #5298.
@ThomasBurleson ThomasBurleson removed the in progress Mainly for in progress PRs, but may be used for issues that require multiple PRs label Jan 19, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests