Skip to content

fix(slide-toggle): disable animations when using NoopAnimationsModule #11414

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 23, 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
9 changes: 8 additions & 1 deletion src/lib/slide-toggle/slide-toggle.scss
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,12 @@ $mat-slide-toggle-bar-track-width: $mat-slide-toggle-bar-width - $mat-slide-togg
// make the drag feeling fast and not delayed.
&.mat-dragging, &:active {
@include cursor-grabbing;

transition-duration: 0ms;
}

._mat-animation-noopable & {
transition: none;
}
}

// The visual thumb element that moves inside of the thumb bar.
Expand Down Expand Up @@ -162,6 +165,10 @@ $mat-slide-toggle-bar-track-width: $mat-slide-toggle-bar-width - $mat-slide-togg
transition: $swift-linear;
transition-property: background-color;
transition-delay: 50ms;

._mat-animation-noopable & {
transition: none;
}
}

// Ripple positioning for the slide-toggle. Moves the ripple container into the center of the thumb.
Expand Down
7 changes: 6 additions & 1 deletion src/lib/slide-toggle/slide-toggle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import {
ViewChild,
ViewEncapsulation,
NgZone,
Optional,
Inject,
} from '@angular/core';
import {ControlValueAccessor, NG_VALUE_ACCESSOR} from '@angular/forms';
import {
Expand All @@ -39,6 +41,7 @@ import {
mixinTabIndex,
RippleRef,
} from '@angular/material/core';
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';

// Increasing integer for generating unique ids for slide-toggle components.
let nextUniqueId = 0;
Expand Down Expand Up @@ -77,6 +80,7 @@ export const _MatSlideToggleMixinBase =
'[class.mat-checked]': 'checked',
'[class.mat-disabled]': 'disabled',
'[class.mat-slide-toggle-label-before]': 'labelPosition == "before"',
'[class._mat-animation-noopable]': '_animationMode === "NoopAnimations"',
},
templateUrl: 'slide-toggle.html',
styleUrls: ['slide-toggle.css'],
Expand Down Expand Up @@ -167,7 +171,8 @@ export class MatSlideToggle extends _MatSlideToggleMixinBase implements OnDestro
private _focusMonitor: FocusMonitor,
private _changeDetectorRef: ChangeDetectorRef,
@Attribute('tabindex') tabIndex: string,
private _ngZone: NgZone) {
private _ngZone: NgZone,
@Optional() @Inject(ANIMATION_MODULE_TYPE) public _animationMode?: string) {

super(elementRef);
this.tabIndex = parseInt(tabIndex) || 0;
Expand Down