Skip to content

Commit 6fbd1a4

Browse files
committed
fix(toggle): fix toggle-class attribute
Closes #1851
1 parent 93d586d commit 6fbd1a4

File tree

5 files changed

+86
-0
lines changed

5 files changed

+86
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
name: simple
3+
component: ionToggle
4+
---
5+
6+
<ion-header-bar class="bar-positive">
7+
<h1 class="title">
8+
Toggle: Simple Usage
9+
</h1>
10+
</ion-header-bar>
11+
<ion-content ng-controller="MainCtrl" class="padding">
12+
<h4>Your pizza has {{toppings()}}!</h4>
13+
<ion-toggle ng-model="pizza.pepperoni">
14+
Pepperoni?
15+
</ion-toggle>
16+
<ion-toggle ng-model="pizza.sausage" toggle-class="toggle-energized">
17+
Sausage?
18+
</ion-toggle>
19+
<ion-toggle ng-model="pizza.jalapenos" toggle-class="toggle-calm">
20+
Jalapeno?
21+
</ion-toggle>
22+
<ion-toggle ng-model="pizza.anchovies" toggle-class="toggle-royal">
23+
Anchovies?
24+
</ion-toggle>
25+
</ion-content>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
name: simple
3+
component: ionToggle
4+
---
5+
6+
var app = angular.module('simple', ['ionic']);
7+
app.controller('MainCtrl', function($scope) {
8+
$scope.pizza = {
9+
pepperoni: true,
10+
sausage: false,
11+
anchovies: true,
12+
jalapenos: false
13+
};
14+
15+
$scope.toppings = function() {
16+
var toppings = Object.keys($scope.pizza).filter(function(flavor) {
17+
return $scope.pizza[flavor];
18+
});
19+
if (toppings.length > 1) {
20+
toppings[toppings.length - 1] = 'and ' + toppings[toppings.length - 1];
21+
}
22+
if (toppings.length > 2) {
23+
return toppings.join(', ');
24+
} else if (toppings.length) {
25+
return toppings.join(' ');
26+
} else {
27+
return 'nothing';
28+
}
29+
};
30+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
name: simple
3+
component: ionToggle
4+
---
5+
6+
it('should uncheck 1st and check 2nd checkbox by clicking its label', function(){
7+
var ele = element.all(by.css('label.toggle'));
8+
ele.get(0).click();
9+
ele.get(1).click();
10+
});
11+
12+
it('should check 1st and uncheck 2nd checkbox by clicking its label', function(){
13+
var ele = element.all(by.css('label.toggle'));
14+
ele.get(0).click();
15+
ele.get(1).click();
16+
});

js/angular/directive/toggle.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ function($ionicGesture, $timeout) {
6161
}
6262
});
6363

64+
if(attr.toggleClass) {
65+
element[0].getElementsByTagName('label')[0].classList.add(attr.toggleClass);
66+
}
67+
6468
return function($scope, $element, $attr) {
6569
var el, checkbox, track, handle;
6670

test/unit/angular/directive/toggle.unit.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,15 @@ describe('Ionic Toggle', function() {
6969

7070
});
7171

72+
it('Should have toggle class', function() {
73+
74+
// Init with not disabled
75+
rootScope.data = { isDisabled: false };
76+
el = compile('<ion-toggle toggle-class="toggle-dark" ng-model="data.name" ng-disabled="data.isDisabled"></ion-toggle>')(rootScope);
77+
78+
// Grab fields
79+
var label = el.find('label');
80+
expect(label.hasClass('toggle-dark')).toEqual(true);
81+
});
82+
7283
});

0 commit comments

Comments
 (0)