Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
feat(switch): add grab/grabbing cursor during drag
Browse files Browse the repository at this point in the history
Closes #983.
  • Loading branch information
ajoslin committed Jan 8, 2015
1 parent 9b16220 commit c60640b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/components/switch/switch.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ function MdSwitch(mdCheckboxDirective, $mdTheming, $mdUtil, $document, $mdConsta

function compile(element, attr) {
var checkboxLink = checkboxDirective.compile(element, attr);
// no transition on initial load
element.addClass('md-dragging');

return function (scope, element, attr, ngModel) {
ngModel = ngModel || $mdUtil.fakeNgModel();
Expand All @@ -76,7 +78,7 @@ function MdSwitch(mdCheckboxDirective, $mdTheming, $mdUtil, $document, $mdConsta

// no transition on initial load
$$rAF(function() {
element.addClass('transition');
element.removeClass('md-dragging');
});

// Tell the checkbox we don't want a click listener.
Expand All @@ -96,7 +98,7 @@ function MdSwitch(mdCheckboxDirective, $mdTheming, $mdUtil, $document, $mdConsta
if (disabledGetter(scope)) return ev.preventDefault();

drag.width = thumbContainer.prop('offsetWidth');
element.removeClass('transition');
element.addClass('md-dragging');
}
function onDrag(ev, drag) {
var percent = drag.distance / drag.width;
Expand All @@ -112,7 +114,7 @@ function MdSwitch(mdCheckboxDirective, $mdTheming, $mdUtil, $document, $mdConsta
function onDragEnd(ev, drag) {
if (disabledGetter(scope)) return false;

element.addClass('transition');
element.removeClass('md-dragging');
thumbContainer.css($mdConstant.CSS.TRANSFORM, '');

// We changed if there is no distance (this is a click a click),
Expand Down
11 changes: 10 additions & 1 deletion src/components/switch/switch.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,22 @@ md-switch {
align-items: center;

.md-container {
cursor: grab;
width: $switch-width;
height: $switch-height;
position: relative;
user-select: none;
margin-right: 8px;
}

// If the user moves his mouse off the switch, stil display grabbing cursor
&:not([disabled]) {
.md-dragging,
&.md-dragging .md-container {
cursor: grabbing;
}
}

.md-label {
border-color: transparent;
border-width: 1px;
Expand Down Expand Up @@ -65,7 +74,7 @@ md-switch {
}
}

&.transition {
&:not(.md-dragging) {
.md-bar,
.md-thumb-container,
.md-thumb {
Expand Down

0 comments on commit c60640b

Please sign in to comment.