Skip to content

Commit 7ed6b37

Browse files
committed
fix(slider): slider emiting changes on slide end when disabled
Currently the slider is firing a change event on slideEnd when it is disabled. If it is disabled and the value of the slider doesn't change, it shouldn't have to emit any change event.
1 parent 60b0625 commit 7ed6b37

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/lib/slider/slider.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,15 @@ describe('MatSlider without forms', () => {
249249
expect(sliderInstance.value).toBe(0);
250250
});
251251

252+
it('should not emit change when disabled', () => {
253+
const onChangeSpy = jasmine.createSpy('slider onChange');
254+
sliderInstance.change.subscribe(onChangeSpy);
255+
256+
dispatchSlideEventSequence(sliderNativeElement, 0, 0.5, gestureConfig);
257+
258+
expect(onChangeSpy).toHaveBeenCalledTimes(0);
259+
});
260+
252261
it('should not add the mat-slider-active class on click when disabled', () => {
253262
expect(sliderNativeElement.classList).not.toContain('mat-slider-active');
254263

src/lib/slider/slider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ export class MatSlider extends _MatSliderMixinBase
518518
_onSlideEnd() {
519519
this._isSliding = false;
520520

521-
if (this._valueOnSlideStart != this.value) {
521+
if (this._valueOnSlideStart != this.value && !this.disabled) {
522522
this._emitChangeEvent();
523523
}
524524
this._valueOnSlideStart = null;

0 commit comments

Comments
 (0)