Skip to content

Commit 89c8474

Browse files
authored
fix(material-experimental/mdc-slider): disable animations when noop module is included (#22649)
Fixes that the MDC-based slider wasn't disabling its animations when noop animations are enabled.
1 parent a1d3467 commit 89c8474

File tree

2 files changed

+16
-33
lines changed

2 files changed

+16
-33
lines changed
Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
@use '@material/slider/slider' as mdc-slider;
2-
@use '../../cdk/a11y';
32
@use '../mdc-helpers/mdc-helpers';
43

54
@include mdc-slider.without-ripple($query: mdc-helpers.$mat-base-styles-query);
65

76
$mat-slider-min-size: 128px !default;
87
$mat-slider-horizontal-margin: 8px !default;
98

10-
// TODO: disabled until we implement the new MDC slider.
11-
// @include mdc-slider-core-styles($query: $mat-base-styles-without-animation-query);
12-
139
// Overwrites the mdc-slider default styles to match the visual appearance of the
1410
// Angular Material standard slider. This involves making the slider an inline-block
1511
// element, aligning it in the vertical middle of a line, specifying a default minimum
@@ -29,32 +25,11 @@ $mat-slider-horizontal-margin: 8px !default;
2925
width: auto;
3026
min-width: $mat-slider-min-size - (2 * $mat-slider-horizontal-margin);
3127

32-
@include a11y.high-contrast(active, off) {
33-
// The slider track isn't visible in high contrast mode so we work
34-
// around it by setting an outline and removing the height to make it look solid.
35-
.mdc-slider__track-container {
36-
height: 0;
37-
outline: solid 2px;
38-
margin-top: 1px;
39-
}
40-
41-
// Adds an outline around the thumb label so it doesn't just float on top of the slider.
42-
.mdc-slider__pin-value-marker {
43-
outline: solid 1px;
28+
&._mat-animation-noopable {
29+
&.mdc-slider--discrete .mdc-slider__thumb,
30+
&.mdc-slider--discrete .mdc-slider__track--active_fill,
31+
.mdc-slider__value-indicator {
32+
transition: none;
4433
}
4534
}
4635
}
47-
48-
// In order to make it possible for developers to disable animations for a slider,
49-
// we only activate the MDC slider animation styles if animations are enabled.
50-
.mat-mdc-slider:not(._mat-animation-noopable) {
51-
// TODO: disabled until we implement the new MDC slider.
52-
// @include mdc-slider-core-styles($query: animation);
53-
}
54-
55-
// Sliders without a thumb label (aka non-discrete) currently cannot have ticks
56-
// enabled. This breaks backwards compatibility with the standard Angular Material
57-
// slider, so we manually ensure that ticks can be rendered.
58-
.mat-slider-has-ticks:not(.mat-slider-disabled) .mdc-slider__track-marker-container {
59-
visibility: visible;
60-
}

src/material-experimental/mdc-slider/slider.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import {
5151
RippleRef,
5252
RippleState,
5353
} from '@angular/material/core';
54+
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';
5455
import {SpecificEventListener, EventType} from '@material/base/types';
5556
import {MDCSliderAdapter, MDCSliderFoundation, Thumb, TickMark} from '@material/slider';
5657
import {Subscription} from 'rxjs';
@@ -206,14 +207,15 @@ export class MatSliderVisualThumb implements AfterViewInit, OnDestroy {
206207

207208
/** Handles displaying the hover ripple. */
208209
private _showHoverRipple(): void {
209-
if (!this._isShowingRipple(this._hoverRippleRef)) {
210+
if (!this._slider._noopAnimations && !this._isShowingRipple(this._hoverRippleRef)) {
210211
this._hoverRippleRef = this._showRipple({ enterDuration: 0, exitDuration: 0 });
211212
this._hoverRippleRef?.element.classList.add('mat-mdc-slider-hover-ripple');
212213
}
213214
}
214215

215216
/** Handles displaying the focus ripple. */
216217
private _showFocusRipple(): void {
218+
// Show the focus ripple event if noop animations are enabled.
217219
if (!this._isShowingRipple(this._focusRippleRef)) {
218220
this._focusRippleRef = this._showRipple({ enterDuration: 0, exitDuration: 0 });
219221
this._focusRippleRef?.element.classList.add('mat-mdc-slider-focus-ripple');
@@ -222,7 +224,7 @@ export class MatSliderVisualThumb implements AfterViewInit, OnDestroy {
222224

223225
/** Handles displaying the active ripple. */
224226
private _showActiveRipple(): void {
225-
if (!this._isShowingRipple(this._activeRippleRef)) {
227+
if (!this._slider._noopAnimations && !this._isShowingRipple(this._activeRippleRef)) {
226228
this._activeRippleRef = this._showRipple({ enterDuration: 225, exitDuration: 400 });
227229
this._activeRippleRef?.element.classList.add('mat-mdc-slider-active-ripple');
228230
}
@@ -529,6 +531,7 @@ const _MatSliderMixinBase:
529531
'[class.mdc-slider--disabled]': 'disabled',
530532
'[class.mdc-slider--discrete]': 'discrete',
531533
'[class.mdc-slider--tick-marks]': 'showTickMarks',
534+
'[class._mat-animation-noopable]': '_noopAnimations',
532535
},
533536
exportAs: 'matSlider',
534537
changeDetection: ChangeDetectionStrategy.OnPush,
@@ -626,6 +629,9 @@ export class MatSlider extends _MatSliderMixinBase
626629
/** The display value of the end thumb. */
627630
_endValueIndicatorText: string;
628631

632+
/** Whether animations have been disabled. */
633+
_noopAnimations: boolean;
634+
629635
/**
630636
* Whether the browser supports pointer events.
631637
*
@@ -648,10 +654,12 @@ export class MatSlider extends _MatSliderMixinBase
648654
@Inject(DOCUMENT) document: any,
649655
@Optional() private _dir: Directionality,
650656
@Optional() @Inject(MAT_RIPPLE_GLOBAL_OPTIONS)
651-
readonly _globalRippleOptions?: RippleGlobalOptions) {
657+
readonly _globalRippleOptions?: RippleGlobalOptions,
658+
@Optional() @Inject(ANIMATION_MODULE_TYPE) animationMode?: string) {
652659
super(_elementRef);
653660
this._document = document;
654661
this._window = this._document.defaultView || window;
662+
this._noopAnimations = animationMode === 'NoopAnimations';
655663
this._dirChangeSubscription = this._dir.change.subscribe(() => this._onDirChange());
656664
this._attachUISyncEventListener();
657665
}

0 commit comments

Comments
 (0)