fix(slide-toggle): emit change event after drag end (#1405)

This commit is contained in:
Paul Gschwendtner
2016-10-06 20:10:29 +02:00
committed by Jeremy Elbourn
parent ec48b34615
commit 0b5b6f2fda
2 changed files with 22 additions and 0 deletions
+21
View File
@@ -486,6 +486,27 @@ describe('MdSlideToggle', () => {
expect(slideThumbContainer.classList).not.toContain('md-dragging');
}));
it('should should emit a change event after drag', fakeAsync(() => {
expect(slideToggle.checked).toBe(false);
gestureConfig.emitEventForElement('slidestart', slideThumbContainer);
expect(slideThumbContainer.classList).toContain('md-dragging');
gestureConfig.emitEventForElement('slide', slideThumbContainer, {
deltaX: 200 // Arbitrary, large delta that will be clamped to the end of the slide-toggle.
});
gestureConfig.emitEventForElement('slideend', slideThumbContainer);
// Flush the timeout for the slide ending.
tick();
expect(slideToggle.checked).toBe(true);
expect(slideThumbContainer.classList).not.toContain('md-dragging');
expect(testComponent.lastEvent.checked).toBe(true);
}));
});
});
+1
View File
@@ -237,6 +237,7 @@ export class MdSlideToggle implements AfterContentInit, ControlValueAccessor {
// because otherwise the click event will be fired and will reset the new checked variable.
setTimeout(() => {
this.checked = this._slideRenderer.stopThumbDrag();
this._emitChangeEvent();
}, 0);
}