Skip to content

Commit cf17ef7

Browse files
crisbetommalerba
authored andcommitted
fix(slider): disable animations when using NoopAnimationsModule (#11422)
Fixes the slider animations not being disabled when the consumer uses the `NoopAnimationsModule`. Relates to #10590.
1 parent 1a75152 commit cf17ef7

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/lib/slider/slider.scss

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,3 +457,18 @@ $mat-slider-focus-ring-size: 30px !default;
457457
}
458458
}
459459
}
460+
461+
// Slider inside a component with disabled animations.
462+
.mat-slider._mat-animation-noopable {
463+
.mat-slider-track-fill,
464+
.mat-slider-track-background,
465+
.mat-slider-ticks,
466+
.mat-slider-thumb-container,
467+
.mat-slider-focus-ring,
468+
.mat-slider-thumb,
469+
.mat-slider-thumb-label,
470+
.mat-slider-thumb-label-text,
471+
.mat-slider-has-ticks .mat-slider-wrapper::after {
472+
transition: none;
473+
}
474+
}

src/lib/slider/slider.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {
3434
Output,
3535
ViewChild,
3636
ViewEncapsulation,
37+
Inject,
3738
} from '@angular/core';
3839
import {ControlValueAccessor, NG_VALUE_ACCESSOR} from '@angular/forms';
3940
import {
@@ -46,6 +47,7 @@ import {
4647
mixinTabIndex,
4748
} from '@angular/material/core';
4849
import {Subscription} from 'rxjs';
50+
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';
4951

5052
/**
5153
* Visually, a 30px separation between tick marks looks best. This is very subjective but it is
@@ -126,6 +128,7 @@ export const _MatSliderMixinBase =
126128
'[class.mat-slider-vertical]': 'vertical',
127129
'[class.mat-slider-min-value]': '_isMinValue',
128130
'[class.mat-slider-hide-last-tick]': 'disabled || _isMinValue && _thumbGap && _invertAxis',
131+
'[class._mat-animation-noopable]': '_animationMode === "NoopAnimations"',
129132
},
130133
templateUrl: 'slider.html',
131134
styleUrls: ['slider.css'],
@@ -431,7 +434,9 @@ export class MatSlider extends _MatSliderMixinBase
431434
private _focusMonitor: FocusMonitor,
432435
private _changeDetectorRef: ChangeDetectorRef,
433436
@Optional() private _dir: Directionality,
434-
@Attribute('tabindex') tabIndex: string) {
437+
@Attribute('tabindex') tabIndex: string,
438+
// @deletion-target 7.0.0 `_animationMode` parameter to be made required.
439+
@Optional() @Inject(ANIMATION_MODULE_TYPE) public _animationMode?: string) {
435440
super(elementRef);
436441

437442
this.tabIndex = parseInt(tabIndex) || 0;

0 commit comments

Comments
 (0)