Skip to content

Commit

Permalink
fix(slide-toggle): emit change event after drag end
Browse files Browse the repository at this point in the history
* Emits a change event after the drag completed.

Fixes #1390.
  • Loading branch information
devversion committed Oct 5, 2016
1 parent 2ee5640 commit 1e16eb2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/lib/slide-toggle/slide-toggle.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 // Use a random number which will be clamped.
});

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);
}));

});

});
Expand Down
1 change: 1 addition & 0 deletions src/lib/slide-toggle/slide-toggle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 1e16eb2

Please sign in to comment.