-
Notifications
You must be signed in to change notification settings - Fork 3.4k
fix(switch): fix switch drag functionality. #6715
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,7 +48,7 @@ angular.module('material.components.switch', [ | |
* | ||
* </hljs> | ||
*/ | ||
function MdSwitch(mdCheckboxDirective, $mdUtil, $mdConstant, $parse, $$rAF, $mdGesture) { | ||
function MdSwitch(mdCheckboxDirective, $mdUtil, $mdConstant, $parse, $$rAF, $mdGesture, $timeout) { | ||
var checkboxDirective = mdCheckboxDirective[0]; | ||
|
||
return { | ||
|
@@ -141,11 +141,17 @@ function MdSwitch(mdCheckboxDirective, $mdUtil, $mdConstant, $parse, $$rAF, $mdG | |
|
||
// We changed if there is no distance (this is a click a click), | ||
// or if the drag distance is >50% of the total. | ||
var isChanged = ngModel.$viewValue ? drag.translate > 0.5 : drag.translate < 0.5; | ||
var isChanged = ngModel.$viewValue ? drag.translate < 0.5 : drag.translate > 0.5; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 noticed this too |
||
if (isChanged) { | ||
applyModelValue(!ngModel.$viewValue); | ||
} | ||
drag = null; | ||
|
||
// Wait for incoming mouse click | ||
scope.skipToggle = true; | ||
$timeout(function() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I really don't like this, iv'e tried to fix this issue myself but also encountered the mouse click issue. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, we are starting the mousedown and leaving the mouseup on the switch element, thats why a click got triggered after the drag got released over the switch. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yet, applying timeout here is just a hack. we should find a way to suspend clicks during drag and re-apply them when the drag ended There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There will be always the same way, to register an click event listener on the overlaying element. I think the more lightweight solution, is to use the current |
||
scope.skipToggle = false; | ||
}, 1); | ||
} | ||
|
||
function applyModelValue(newValue) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@EladBezalel Should I add a comment here to explain what
skipToggle
is used for?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes plz
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!