Skip to content
This repository was archived by the owner on Dec 3, 2021. It is now read-only.

Commit a83975c

Browse files
author
Adam DiCarlo
committed
Allow empty labels via attrs.
1 parent 19ccd1e commit a83975c

2 files changed

Lines changed: 29 additions & 4 deletions

File tree

angular-toggle-switch.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@
3535
'</div>' +
3636
'</div>',
3737
compile: function(element, attrs) {
38-
if (!attrs.onLabel) { attrs.onLabel = toggleSwitchConfig.onLabel; }
39-
if (!attrs.offLabel) { attrs.offLabel = toggleSwitchConfig.offLabel; }
40-
if (!attrs.knobLabel) { attrs.knobLabel = toggleSwitchConfig.knobLabel; }
38+
if (angular.isUndefined(attrs.onLabel)) { attrs.onLabel = toggleSwitchConfig.onLabel; }
39+
if (angular.isUndefined(attrs.offLabel)) { attrs.offLabel = toggleSwitchConfig.offLabel; }
40+
if (angular.isUndefined(attrs.knobLabel)) { attrs.knobLabel = toggleSwitchConfig.knobLabel; }
4141

4242
return this.link;
4343
},

test/angular-toggle-switch.spec.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
describe('Toggle Switch', function() {
2-
var $scope, $compile;
2+
var $scope, $compile, isolateScope;
33

44
var baseTemplate = '<toggle-switch ng-model="switchState">\n</toggle-switch>';
5+
var emptyOnLabelTemplate = '<toggle-switch ng-model="switchState" on-label="">\n</toggle-switch>';
6+
var emptyOffLabelTemplate = '<toggle-switch ng-model="switchState" off-label="">\n</toggle-switch>';
7+
var emptyKnobLabelTemplate = '<toggle-switch ng-model="switchState" knob-label="">\n</toggle-switch>';
58
var onLabelTemplate = '<toggle-switch ng-model="switchState" on-label="CUSTOM-ON">\n</toggle-switch>';
69
var offLabelTemplate = '<toggle-switch ng-model="switchState" off-label="CUSTOM-OFF">\n</toggle-switch>';
710
var knobLabelTemplate = '<toggle-switch ng-model="switchState" knob-label="CUSTOM">\n</toggle-switch>';
@@ -22,6 +25,7 @@ describe('Toggle Switch', function() {
2225
var elm = angular.element(template);
2326
$compile(elm)(scope);
2427
scope.$apply();
28+
isolateScope = elm.isolateScope();
2529
return elm;
2630
}
2731

@@ -96,6 +100,13 @@ describe('Toggle Switch', function() {
96100
});
97101
});
98102

103+
describe('with an empty `on-label`', function() {
104+
it('sets the label empty', function() {
105+
var elm = compileDirective(emptyOnLabelTemplate, $scope);
106+
expect(isolateScope.onLabel).toEqual('');
107+
});
108+
});
109+
99110
describe('when there is a custom `off-label`', function () {
100111
// @TODO: figure out how to deal with html in Angular 1.2
101112
//describe('is html', function() {
@@ -113,13 +124,27 @@ describe('Toggle Switch', function() {
113124
});
114125
});
115126

127+
describe('with an empty `off-label`', function() {
128+
it('sets the label empty', function() {
129+
var elm = compileDirective(emptyOffLabelTemplate, $scope);
130+
expect(isolateScope.offLabel).toEqual('');
131+
});
132+
});
133+
116134
describe('when there is a custom `knob-label`', function () {
117135
it('sets the on label', function() {
118136
var elm = compileDirective(knobLabelTemplate, $scope);
119137
expect(elm.text()).toContain('CUSTOM');
120138
});
121139
});
122140

141+
describe('with an empty `knob-label`', function() {
142+
it('sets the label empty', function() {
143+
var elm = compileDirective(emptyKnobLabelTemplate, $scope);
144+
expect(isolateScope.knobLabel).toEqual('');
145+
});
146+
});
147+
123148
describe('when toggle is disabled', function() {
124149
it('ngModel does not change on click', function() {
125150
$scope.switchState = true;

0 commit comments

Comments
 (0)