-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
fix(progress-bar/progress-spinner): prevent animations when in a noopanimations module context #10881
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// If the mat-animation-noop class is present on the components root element, | ||
// 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() { | ||
// @at-root is used to steps outside of the hierarchy of the scss rules. This is | ||
// done to allow a class to be added to be added to base of the scss nesting | ||
// context. | ||
// For example: | ||
// .my-root { | ||
// .my-subclass { | ||
// @include _noop-animation() | ||
// } | ||
// } | ||
// results in: | ||
// ._mat-animation-noopable.my-root .my-subclass { ... } | ||
@at-root ._mat-animation-noopable#{&} { | ||
transition: none; | ||
animation: none; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,9 +9,12 @@ import { | |
Component, | ||
ChangeDetectionStrategy, | ||
ElementRef, | ||
Inject, | ||
Input, | ||
Optional, | ||
ViewEncapsulation | ||
} from '@angular/core'; | ||
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
import {CanColor, mixinColor} from '@angular/material/core'; | ||
|
||
// TODO(josephperrott): Benchpress tests. | ||
|
@@ -42,6 +45,7 @@ let progressbarId = 0; | |
'[attr.aria-valuenow]': 'value', | ||
'[attr.mode]': 'mode', | ||
'class': 'mat-progress-bar', | ||
'[class._mat-animation-noopable]': `_animationMode === 'NoopAnimations'`, | ||
}, | ||
inputs: ['color'], | ||
templateUrl: 'progress-bar.html', | ||
|
@@ -51,7 +55,9 @@ let progressbarId = 0; | |
}) | ||
export class MatProgressBar extends _MatProgressBarMixinBase implements CanColor { | ||
|
||
constructor(public _elementRef: ElementRef) { | ||
|
||
constructor(public _elementRef: ElementRef, | ||
@Optional() @Inject(ANIMATION_MODULE_TYPE) public _animationMode?: string) { | ||
super(_elementRef); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_mat-noop-animation
There was a problem hiding this comment.
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