Skip to content

fix(slider): change event is not being emitted #7278

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
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
27 changes: 27 additions & 0 deletions src/lib/slider/slider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,33 @@ describe('MdSlider without forms', () => {
expect(sliderNativeElement.classList).not.toContain('mat-slider-sliding');
});

it('should not change value without emitting a change event', () => {
const onChangeSpy = jasmine.createSpy('slider onChange');

sliderInstance.change.subscribe(onChangeSpy);
sliderInstance.value = 50;
fixture.detectChanges();

dispatchSlideStartEvent(sliderNativeElement, 0, gestureConfig);
fixture.detectChanges();

dispatchSlideEvent(sliderNativeElement, 10, gestureConfig);
fixture.detectChanges();

// In some situations, HammerJS will fire a second "slidestart" event because the user
// holds the thumb and drags it around. This would mean that the `_valueOnSlideStart`
// value will be updated to the actual end value. Causing the slider to think that the value
// didn't change at all.
dispatchSlideStartEvent(sliderNativeElement, 10, gestureConfig);
fixture.detectChanges();

dispatchSlideEndEvent(sliderNativeElement, 10, gestureConfig);
fixture.detectChanges();

expect(sliderNativeElement.classList).not.toContain('mat-slider-sliding');
expect(onChangeSpy).toHaveBeenCalledTimes(1);
});

it('should reset active state upon blur', () => {
sliderInstance._isActive = true;

Expand Down
2 changes: 1 addition & 1 deletion src/lib/slider/slider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ export class MdSlider extends _MdSliderMixinBase
}

_onSlideStart(event: HammerInput | null) {
if (this.disabled) {
if (this.disabled || this._isSliding) {
return;
}

Expand Down