Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit c60640b

Browse files
committed
feat(switch): add grab/grabbing cursor during drag
Closes #983.
1 parent 9b16220 commit c60640b

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

src/components/switch/switch.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ function MdSwitch(mdCheckboxDirective, $mdTheming, $mdUtil, $document, $mdConsta
6767

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

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

7779
// no transition on initial load
7880
$$rAF(function() {
79-
element.addClass('transition');
81+
element.removeClass('md-dragging');
8082
});
8183

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

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

115-
element.addClass('transition');
117+
element.removeClass('md-dragging');
116118
thumbContainer.css($mdConstant.CSS.TRANSFORM, '');
117119

118120
// We changed if there is no distance (this is a click a click),

src/components/switch/switch.scss

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,22 @@ md-switch {
99
align-items: center;
1010

1111
.md-container {
12+
cursor: grab;
1213
width: $switch-width;
1314
height: $switch-height;
1415
position: relative;
1516
user-select: none;
1617
margin-right: 8px;
1718
}
1819

20+
// If the user moves his mouse off the switch, stil display grabbing cursor
21+
&:not([disabled]) {
22+
.md-dragging,
23+
&.md-dragging .md-container {
24+
cursor: grabbing;
25+
}
26+
}
27+
1928
.md-label {
2029
border-color: transparent;
2130
border-width: 1px;
@@ -65,7 +74,7 @@ md-switch {
6574
}
6675
}
6776

68-
&.transition {
77+
&:not(.md-dragging) {
6978
.md-bar,
7079
.md-thumb-container,
7180
.md-thumb {

0 commit comments

Comments
 (0)