mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
fix(slide-toggle): emit change event after drag end (#1405)
This commit is contained in:
committed by
Jeremy Elbourn
parent
ec48b34615
commit
0b5b6f2fda
@@ -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);
|
||||
}));
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user