Skip to content

Commit f4745c3

Browse files
author
Adam Bradley
committed
enable/disable toggle pointer-events w/ css only, closes #1185
1 parent b626688 commit f4745c3

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

js/angular/directive/toggle.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ function($ionicGesture, $timeout) {
3131
ngDisabled: '=?'
3232
},
3333
transclude: true,
34-
template: '<div class="item item-toggle disable-pointer-events">' +
34+
template: '<div class="item item-toggle">' +
3535
'<div ng-transclude></div>' +
36-
'<label class="toggle enable-pointer-events">' +
36+
'<label class="toggle">' +
3737
'<input type="checkbox" ng-model="ngModel" ng-value="ngValue" ng-change="ngChange()" ng-disabled="ngDisabled">' +
38-
'<div class="track disable-pointer-events">' +
38+
'<div class="track">' +
3939
'<div class="handle"></div>' +
4040
'</div>' +
4141
'</label>' +

scss/_toggle.scss

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@
44
* --------------------------------------------------
55
*/
66

7-
/* the overall container of the toggle */
7+
.item-toggle {
8+
pointer-events: none;
9+
}
10+
811
.toggle {
912
// set the color defaults
1013
@include toggle-style($toggle-on-default-border, $toggle-on-default-bg);
1114

1215
position: relative;
1316
display: inline-block;
17+
pointer-events: auto;
1418
margin: -$toggle-hit-area-expansion;
1519
padding: $toggle-hit-area-expansion;
1620

@@ -49,8 +53,8 @@
4953
}
5054
}
5155

52-
/* hide the actual input checkbox */
5356
.toggle input {
57+
// hide the actual input checkbox
5458
display: none;
5559
}
5660

@@ -69,23 +73,24 @@
6973
background-color: $toggle-off-bg-color;
7074
content: ' ';
7175
cursor: pointer;
76+
pointer-events: none;
7277
}
7378

7479
/* the handle (circle) thats inside the toggle's track area */
7580
/* also the handle's appearance when it is "off" */
7681
.toggle .handle {
7782
@include transition($toggle-transition-duration ease-in-out);
7883
position: absolute;
79-
top: $toggle-border-width + $toggle-hit-area-expansion;
80-
left: $toggle-border-width + $toggle-hit-area-expansion;
8184
display: block;
8285
width: $toggle-handle-width;
8386
height: $toggle-handle-height;
8487
border-radius: $toggle-handle-radius;
8588
background-color: $toggle-handle-off-bg-color;
89+
top: $toggle-border-width + $toggle-hit-area-expansion;
90+
left: $toggle-border-width + $toggle-hit-area-expansion;
8691

87-
/* used to create a larger (but hidden) hit area to slide the handle */
8892
&:before {
93+
// used to create a larger (but hidden) hit area to slide the handle
8994
position: absolute;
9095
top: -4px;
9196
left: ( ($toggle-handle-width / 2) * -1) - 8;
@@ -94,23 +99,23 @@
9499
}
95100
}
96101

97-
/* the handle when the toggle is "on" */
98102
.toggle input:checked + .track .handle {
103+
// the handle when the toggle is "on"
99104
@include translate3d($toggle-width - $toggle-handle-width - ($toggle-border-width * 2), 0, 0);
100105
background-color: $toggle-handle-on-bg-color;
101106
}
102107

103-
/* make sure list item content have enough padding on right to fit the toggle */
104108
.item-toggle {
109+
// make sure list item content have enough padding on right to fit the toggle
105110
padding-right: ($item-padding * 3) + $toggle-width;
106111

107112
&.active {
108113
box-shadow: none;
109114
}
110115
}
111116

112-
/* position the toggle to the right within a list item */
113117
.item-toggle .toggle {
118+
// position the toggle to the right within a list item
114119
position: absolute;
115120
top: $item-padding / 2;
116121
right: $item-padding;

test/html/tapInputs.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@
6969
<input type="checkbox" ng-model="toggle2" ng-true-value="yup" ng-false-value="nope">,
7070
</div>
7171

72+
<li ng-if="true" class="item item-toggle">
73+
<label class="toggle">
74+
<input type="checkbox">
75+
<div class="track">
76+
<div class="handle"></div>
77+
</div>
78+
</label>
79+
HTML Only
80+
</li>
81+
7282
<div class="item item-divider">
7383
Radio
7484
</div>

0 commit comments

Comments
 (0)