Skip to content

Commit 1e2fe90

Browse files
llorenspujoljelbourn
authored andcommitted
fix(slider): slider emiting changes on slide end when disabled (#9434)
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 0a63031 commit 1e2fe90

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
@@ -534,7 +534,7 @@ export class MatSlider extends _MatSliderMixinBase
534534
_onSlideEnd() {
535535
this._isSliding = false;
536536

537-
if (this._valueOnSlideStart != this.value) {
537+
if (this._valueOnSlideStart != this.value && !this.disabled) {
538538
this._emitChangeEvent();
539539
}
540540
this._valueOnSlideStart = null;

0 commit comments

Comments
 (0)