Skip to content

fix(progress-bar/progress-spinner): prevent animations when in a noopanimations module context #10881

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 4, 2018

Conversation

josephperrott
Copy link
Member

@josephperrott josephperrott commented Apr 16, 2018

For #10590

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Apr 16, 2018
Copy link
Contributor

@mmalerba mmalerba left a comment

Choose a reason for hiding this comment

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

change title to fix(progress-bar/progress-spinner): ...

@@ -0,0 +1,9 @@
// If the mat-animation-noop class is present on the components root element,
// prevent non css animations from running.
@mixin noop-animation() {
Copy link
Contributor

Choose a reason for hiding this comment

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

mat-noopable-animation?

Copy link
Member

Choose a reason for hiding this comment

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

I would also prefix it with an underscore

// If the mat-animation-noop class is present on the components root element,
// prevent non css animations from running.
@mixin noop-animation() {
@at-root .mat-animation-noop#{&} {
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this one be wrapped by the at-root?

@at-root {
  .mat-animation-noop {
    ...
   }
}

Copy link
Member Author

Choose a reason for hiding this comment

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

If you do

@at-root {
  .mat-animation-noop {
    ...
   }
}

It ends up as
root-element-thing .mat-animation-noop, but we want root-element-thing.mat-animation-noop

ViewEncapsulation
} from '@angular/core';
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't adding this import be considered a breaking change, in the case where somebody might not have the animations package? I think we had a discussion along the same lines with @mmalerba where we considered adding animations to a component, that didn't have any, a breaking change. That being said, most people should have platform-browser already.

Copy link
Member

Choose a reason for hiding this comment

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

I think this is different because it doesn't require a module to be loaded; for animations, the breaking change is that you need to include BrowserAnimationsModule at the root for it to work. For this, I don't think it actually breaks anything.

@@ -144,7 +146,8 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements

constructor(public _elementRef: ElementRef,
platform: Platform,
@Optional() @Inject(DOCUMENT) private _document: any) {
@Optional() @Inject(DOCUMENT) private _document: any,
@Optional() @Inject(ANIMATION_MODULE_TYPE) public _animationMode: string) {
Copy link
Member

Choose a reason for hiding this comment

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

The _animationMode param should also be marked as optional, in case anybody was extending the component.

@@ -20,7 +20,7 @@ import {AccessibilityDemoModule} from './a11y/a11y-module';
@NgModule({
imports: [
BrowserModule,
BrowserAnimationsModule,
NoopAnimationsModule,
Copy link
Member

Choose a reason for hiding this comment

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

We don't want to switch the demo-app completely to noop. It should only be for some specific section you want to test.

Copy link
Member Author

Choose a reason for hiding this comment

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

Whoops.

@@ -0,0 +1,9 @@
// If the mat-animation-noop class is present on the components root element,
// prevent non css animations from running.
@mixin noop-animation() {
Copy link
Member

Choose a reason for hiding this comment

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

I would also prefix it with an underscore

ViewEncapsulation
} from '@angular/core';
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';
Copy link
Member

Choose a reason for hiding this comment

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

I think this is different because it doesn't require a module to be loaded; for animations, the breaking change is that you need to include BrowserAnimationsModule at the root for it to work. For this, I don't think it actually breaks anything.


$mat-progress-bar-height: 5px !default;
$mat-progress-bar-full-animation-duration: 2000ms !default;
$mat-progress-bar-piece-animation-duration: 250ms !default;


.mat-progress-bar {
@include noop-animation();
Copy link
Member

Choose a reason for hiding this comment

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

I'm not a fan of the way the mixin is peppered throughout the file in so many places. Let's take a look next week to see what it would look like with the noop animations code in one place.

@josephperrott josephperrott changed the title fix(animations): prevent animations when in a noopanimations module context fix(progress-bar/progress-spinner\): prevent animations when in a noopanimations module context Apr 24, 2018
@josephperrott josephperrott changed the title fix(progress-bar/progress-spinner\): prevent animations when in a noopanimations module context fix(progress-bar/progress-spinner): prevent animations when in a noopanimations module context Apr 24, 2018
@josephperrott josephperrott force-pushed the animation-noop branch 2 times, most recently from 2aa3839 to ee2ef0e Compare April 24, 2018 17:56
// If the mat-animation-noop class is present on the components root element,
// prevent non css animations from running.
@mixin _noop-animation() {
@at-root .mat-animation-noop#{&} {
Copy link
Member

Choose a reason for hiding this comment

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

Add comment that explains why @at-root is used here, perhaps with an example?

// prevent non css animations from running.
@mixin _noop-animation() {
@at-root .mat-animation-noop#{&} {
transition-property: none;
Copy link
Member

Choose a reason for hiding this comment

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

You probably don't need transition-property

// prevent non css animations from running.
// NOTE: Currently this mixin should only be used with components that do not
// have any projected content.
@mixin _noop-animation() {
Copy link
Member

Choose a reason for hiding this comment

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

_mat-noop-animation

Copy link
Contributor

Choose a reason for hiding this comment

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

can we call it noopable? it's not nooping the animation, it's just making it noopable in case you add the noop class

@josephperrott josephperrott added the target: minor This PR is targeted for the next minor release label May 4, 2018
@mmalerba mmalerba added pr: lgtm action: merge The PR is ready for merge by the caretaker labels May 4, 2018
@josephperrott josephperrott merged commit 81b6a78 into angular:master May 4, 2018
@josephperrott josephperrott deleted the animation-noop branch May 4, 2018 20:12
@bennyboer
Copy link

Hi there!

It does not make sense to me to disable animations on a progress spinner, as this is a functional animation not just for visuals.
Who would need progress spinners which do not move at all?

@carlosperezortola
Copy link

Bennyboer is correct. Why would you want to disable the progress bars? A loading screen looks then broken.

@crisbeto
Copy link
Member

crisbeto commented Apr 4, 2019

The main use case for this is something like e2e or screenshot tests where your results could be thrown off by the animation.

@bennyboer
Copy link

The main use case for this is something like e2e or screenshot tests where your results could be thrown off by the animation.

You can force the animations of the progress spinner using the MAT_PROGRESS_SPINNER_DEFAULT_OPTIONS injection token, but this is not documented anywhere.
I don't understand why there are no hidden switches then for these specific tests to turn off animations instead of turning them off by default when using the NoopAnimationsModule.

I created an issue as this is not the correct place to discuss that.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants