Skip to content

fix(form-field): disable all animations when using NoopAnimationsModule #11371

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

Merged
merged 1 commit into from
May 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/lib/form-field/form-field-fill.scss
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ $mat-form-field-fill-subscript-padding:
}
}

&._mat-animation-noopable:not(.mat-form-field-disabled) .mat-form-field-flex:hover {
& ~ .mat-form-field-underline .mat-form-field-ripple {
transition: none;
}
}

.mat-form-field-subscript-wrapper {
padding: 0 $mat-form-field-fill-subscript-padding;
}
Expand Down
10 changes: 10 additions & 0 deletions src/lib/form-field/form-field-outline.scss
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,14 @@ $mat-form-field-outline-subscript-padding:
.mat-form-field-subscript-wrapper {
padding: 0 $mat-form-field-outline-subscript-padding;
}

&._mat-animation-noopable {
&:not(.mat-form-field-disabled) .mat-form-field-flex:hover ~ .mat-form-field-outline,
.mat-form-field-outline,
.mat-form-field-outline-start,
.mat-form-field-outline-end,
.mat-form-field-outline-gap {
transition: none;
}
}
}
6 changes: 6 additions & 0 deletions src/lib/form-field/form-field-standard.scss
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,10 @@ $mat-form-field-standard-padding-top: 0.75em !default;
transition: opacity 600ms $swift-ease-out-timing-function;
}
}

&._mat-animation-noopable:not(.mat-form-field-disabled) .mat-form-field-flex:hover {
& ~ .mat-form-field-underline .mat-form-field-ripple {
transition: none;
}
}
}
7 changes: 7 additions & 0 deletions src/lib/form-field/form-field.scss
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,10 @@ $mat-form-field-default-infix-width: 180px !default;
.mat-error {
display: block;
}

.mat-form-field._mat-animation-noopable {
.mat-form-field-label,
.mat-form-field-ripple {
transition: none;
}
}
27 changes: 18 additions & 9 deletions src/lib/form-field/form-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import {MatPlaceholder} from './placeholder';
import {MatPrefix} from './prefix';
import {MatSuffix} from './suffix';
import {Platform} from '@angular/cdk/platform';
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';


let nextUniqueId = 0;
Expand Down Expand Up @@ -130,6 +131,7 @@ export const MAT_FORM_FIELD_DEFAULT_OPTIONS =
'[class.ng-valid]': '_shouldForward("valid")',
'[class.ng-invalid]': '_shouldForward("invalid")',
'[class.ng-pending]': '_shouldForward("pending")',
'[class._mat-animation-noopable]': '!_animationsEnabled',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the class name we used in other components? The _ seems unnecessary

Copy link
Member Author

@crisbeto crisbeto May 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I kept it for consistency with the other components, but I'm not sure where the underscore comes from @josephperrott.

},
inputs: ['color'],
encapsulation: ViewEncapsulation.None,
Expand Down Expand Up @@ -204,10 +206,11 @@ export class MatFormField extends _MatFormFieldMixinBase
}
private _floatLabel: FloatLabelType;

_outlineGapWidth = 0;
/** Whether the Angular animations are enabled. */
_animationsEnabled: boolean;

_outlineGapWidth = 0;
_outlineGapStart = 0;

_initialGapCalculated = false;

/**
Expand All @@ -234,13 +237,15 @@ export class MatFormField extends _MatFormFieldMixinBase
@Optional() private _dir: Directionality,
@Optional() @Inject(MAT_FORM_FIELD_DEFAULT_OPTIONS) private _defaultOptions:
MatFormFieldDefaultOptions,
// @deletion-target 7.0.0 _platform and _ngZone to be made required.
// @deletion-target 7.0.0 _platform, _ngZone and _animationMode to be made required.
private _platform?: Platform,
private _ngZone?: NgZone) {
private _ngZone?: NgZone,
@Optional() @Inject(ANIMATION_MODULE_TYPE) _animationMode?: string) {
super(_elementRef);

this._labelOptions = labelOptions ? labelOptions : {};
this.floatLabel = this._labelOptions.float || 'auto';
this._animationsEnabled = _animationMode !== 'NoopAnimations';
}

/**
Expand Down Expand Up @@ -345,13 +350,17 @@ export class MatFormField extends _MatFormFieldMixinBase
/** Animates the placeholder up and locks it in position. */
_animateAndLockLabel(): void {
if (this._hasFloatingLabel() && this._canLabelFloat) {
this._showAlwaysAnimate = true;
this.floatLabel = 'always';
// If animations are disabled, we shouldn't go in here,
// because the `transitionend` will never fire.
if (this._animationsEnabled) {
this._showAlwaysAnimate = true;

fromEvent(this._label.nativeElement, 'transitionend').pipe(take(1)).subscribe(() => {
this._showAlwaysAnimate = false;
});
fromEvent(this._label.nativeElement, 'transitionend').pipe(take(1)).subscribe(() => {
this._showAlwaysAnimate = false;
});
}

this.floatLabel = 'always';
this._changeDetectorRef.markForCheck();
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/input/input.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
MatFormFieldModule,
} from '@angular/material/form-field';
import {By} from '@angular/platform-browser';
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
import {MatInputModule} from './index';
import {MatInput} from './input';
import {MatStepperModule} from '@angular/material/stepper';
Expand Down Expand Up @@ -1203,7 +1203,7 @@ function createComponent<T>(component: Type<T>,
FormsModule,
MatFormFieldModule,
MatInputModule,
NoopAnimationsModule,
BrowserAnimationsModule,
PlatformModule,
ReactiveFormsModule,
...imports
Expand Down