Skip to content

Commit bcca397

Browse files
committed
fix(ionTabBar): fix iconOn and iconOff being wrong
1 parent b5133f2 commit bcca397

File tree

2 files changed

+45
-15
lines changed

2 files changed

+45
-15
lines changed

js/ext/angular/src/directive/ionicTabBar.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,8 @@ function($scope, $ionicViewService, $rootScope, $element) {
245245
'<a ng-class="{active: isTabActive(), \'has-badge\':badge}" ' +
246246
'ng-click="selectTab($event)" class="tab-item">' +
247247
'<span class="badge {{badgeStyle}}" ng-if="badge">{{badge}}</span>' +
248-
'<i class="icon {{iconOn}}" ng-if="iconOn && isTabActive()"></i>' +
249-
'<i class="icon {{iconOff}}" ng-if="iconOff && !isTabActive()"></i>' +
248+
'<i class="icon {{getIconOn()}}" ng-if="getIconOn() && isTabActive()"></i>' +
249+
'<i class="icon {{getIconOff()}}" ng-if="getIconOff() && !isTabActive()"></i>' +
250250
'<span class="tab-title" ng-bind-html="title"></span>' +
251251
'</a>',
252252
scope: {
@@ -258,14 +258,17 @@ function($scope, $ionicViewService, $rootScope, $element) {
258258
badgeStyle: '@'
259259
},
260260
compile: function(element, attr, transclude) {
261-
if (attr.icon) {
262-
attr.$set('iconOn', attr.icon);
263-
attr.$set('iconOff', attr.icon);
264-
}
265261
return function link($scope, $element, $attrs, ctrls) {
266262
var tabsCtrl = ctrls[0],
267263
tabCtrl = ctrls[1];
268264

265+
$scope.getIconOn = function() {
266+
return $scope.iconOn || $scope.icon;
267+
};
268+
$scope.getIconOff = function() {
269+
return $scope.iconOff || $scope.icon;
270+
};
271+
269272
$scope.isTabActive = function() {
270273
return tabsCtrl.selectedTab === tabCtrl.$scope;
271274
};

js/ext/angular/test/directive/ionicTabBar.unit.js

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
describe('tabs', function() {
1+
ddescribe('tabs', function() {
22

33
describe('miscellaneous', function() {
44
beforeEach(module('ionic', function($provide) {
@@ -387,10 +387,21 @@ describe('tabs', function() {
387387
expect(tabsCtrl.select).toHaveBeenCalledWith(tabCtrl.$scope, true);
388388
});
389389

390-
it('should set iconOn and iconOff to icon if icon is given', function() {
390+
it('should fallback to icon for icon-on and icon-off', function() {
391391
var el = setup('icon=1');
392-
expect(el.attr('icon-on')).toBe('1');
393-
expect(el.attr('icon-off')).toBe('1');
392+
393+
expect(el.isolateScope().getIconOn()).toBe('1');
394+
el.isolateScope().iconOn = 2;
395+
expect(el.isolateScope().getIconOn()).toBe(2);
396+
el.isolateScope().iconOn = null;
397+
expect(el.isolateScope().getIconOn()).toBe('1');
398+
399+
expect(el.isolateScope().getIconOff()).toBe('1');
400+
el.isolateScope().iconOff = 3;
401+
expect(el.isolateScope().getIconOff()).toBe(3);
402+
el.isolateScope().iconOff = null;
403+
expect(el.isolateScope().getIconOff()).toBe('1');
404+
394405
});
395406

396407
it('should select tab on click', function() {
@@ -408,20 +419,36 @@ describe('tabs', function() {
408419
el.scope().$apply('name = "joe"');
409420
expect(el.find('.tab-title').html()).toBe('<b>hi, joe!</b>');
410421
});
422+
423+
it('should change icon class with just icon', function() {
424+
//In this case, icon-on and icon-off should be same
425+
var el = setup('icon={{icon}}');
426+
el.scope().icon="superIcon";
427+
el.scope().$apply();
428+
429+
el.isolateScope().isTabActive = function() { return true; };
430+
el.isolateScope().$apply();
431+
432+
expect(el.find('.icon.superIcon').length).toBe(1);
433+
el.isolateScope().isTabActive = function() { return false; };
434+
el.isolateScope().$apply();
435+
436+
expect(el.find('.icon.superIcon').length).toBe(1);
437+
});
411438
it('should change classes based on active', function() {
412-
var el = setup('icon-on=on icon-off=off');
439+
var el = setup('icon-on="{{true}}" icon-off="{{false}}"');
413440

414441
el.isolateScope().isTabActive = function() { return true; };
415442
el.isolateScope().$apply();
416443
expect(el.hasClass('active')).toBe(true);
417-
expect(el.find('.icon.on').length).toBe(1);
418-
expect(el.find('.icon.off').length).toBe(0);
444+
expect(el.find('.icon.true').length).toBe(1);
445+
expect(el.find('.icon.false').length).toBe(0);
419446

420447
el.isolateScope().isTabActive = function() { return false; };
421448
el.isolateScope().$apply();
422449
expect(el.hasClass('active')).toBe(false);
423-
expect(el.find('.icon.on').length).toBe(0);
424-
expect(el.find('.icon.off').length).toBe(1);
450+
expect(el.find('.icon.true').length).toBe(0);
451+
expect(el.find('.icon.false').length).toBe(1);
425452
});
426453
it('shouldnt has-badge without badge', function() {
427454
var el = setup();

0 commit comments

Comments
 (0)