Skip to content

Commit

Permalink
fix(tab): tabs are now styled directly via dom manipulations
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Bucholtz committed Apr 11, 2016
1 parent 6478b5d commit fbae1ab
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 37 deletions.
2 changes: 2 additions & 0 deletions js/angular/controller/tabsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ function($scope, $element, $ionicHistory) {
uiSref: tab.uiSref
});
}

$scope.$broadcast("tabSelected", { selectedTab: tab, selectedTabIndex: tabIndex});
}
};

Expand Down
35 changes: 32 additions & 3 deletions js/angular/directive/tabNav.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ IonicModule
replace: true,
require: ['^ionTabs', '^ionTab'],
template:
'<a ng-class="{\'tab-item-active\': isTabActive(), \'has-badge\':badge, \'tab-hidden\':isHidden()}" ' +
'<a ng-class="{\'has-badge\':badge, \'tab-hidden\':isHidden()}" ' +
' ng-disabled="disabled()" class="tab-item">' +
'<span class="badge {{badgeStyle}}" ng-if="badge">{{badge}}</span>' +
'<i class="icon {{getIconOn()}}" ng-if="getIconOn() && isTabActive()"></i>' +
'<i class="icon {{getIconOff()}}" ng-if="getIconOff() && !isTabActive()"></i>' +
'<i class="icon"></i>' +
'<span class="tab-title" ng-bind-html="title"></span>' +
'</a>',
scope: {
Expand Down Expand Up @@ -57,6 +56,36 @@ IonicModule
$scope.isTabActive = function() {
return tabsCtrl.selectedTab() === tabCtrl.$scope;
};

$scope.$watch("icon", function() {
styleTab();
});

$scope.$watch("iconOff", function() {
styleTab();
});

$scope.$watch("iconOn", function() {
styleTab();
});

function styleTab() {
// check if tab if active
if ( tabsCtrl.selectedTab() === tabCtrl.$scope ) {
$element.addClass('tab-item-active');
$element.find('i').removeClass($scope.getIconOff());
$element.find('i').addClass($scope.getIconOn());
}
else {
$element.removeClass('tab-item-active');
$element.find('i').removeClass($scope.getIconOn());
$element.find('i').addClass($scope.getIconOff());
}
}

$scope.$on("tabSelected", styleTab);

styleTab();
}
};
}]);
9 changes: 8 additions & 1 deletion test/unit/angular/directive/tabs.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -649,14 +649,21 @@ describe('tabs', function() {
it('should change classes based on active', function() {
var el = setup('icon-on="{{true}}" icon-off="{{false}}"');

el.isolateScope().isTabActive = function() { return true; };
tabsCtrl.selectedTab = function(){
return tabCtrl.$scope;
}
el.isolateScope().$apply();
el.isolateScope().$broadcast("tabSelected", {});
expect(el.hasClass('tab-item-active')).toBe(true);
expect(el.find('.icon.true').length).toBe(1);
expect(el.find('.icon.false').length).toBe(0);

tabsCtrl.selectedTab = function(){
return "somenthing that isn't the selected tab";
}
el.isolateScope().isTabActive = function() { return false; };
el.isolateScope().$apply();
el.isolateScope().$broadcast("tabSelected", {});
expect(el.hasClass('tab-item-active')).toBe(false);
expect(el.find('.icon.true').length).toBe(0);
expect(el.find('.icon.false').length).toBe(1);
Expand Down
62 changes: 29 additions & 33 deletions test/unit/utils/tap.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -1296,53 +1296,49 @@ describe('Ionic Tap', function() {

it('Should not isKeyboardElement on date and select on Android and iPad', function() {

if ( ! /PhantomJS/.test(window.navigator.userAgent) ){
// these test cases don't work in phantom due to phantom bug, but do work in chrome
expect( ionic.tap.isKeyboardElement(null) ).toEqual(false);
expect( ionic.tap.isKeyboardElement(null) ).toEqual(false);

ionic.Platform.setPlatform('android');
ionic.Platform.setPlatform('android');

var ele = document.createElement('input');
ele.type = 'date';
expect( ionic.tap.isKeyboardElement(ele) ).toEqual(false);
var ele = { type:'date'};
expect( ionic.tap.isKeyboardElement(ele) ).toEqual(false);

ele.type = 'datetime-local';
expect( ionic.tap.isKeyboardElement(ele) ).toEqual(false);
ele.type = 'datetime-local';
expect( ionic.tap.isKeyboardElement(ele) ).toEqual(false);

ele.type = 'month';
expect( ionic.tap.isKeyboardElement(ele) ).toEqual(false);
ele.type = 'month';
expect( ionic.tap.isKeyboardElement(ele) ).toEqual(false);

ele.type = 'week';
expect( ionic.tap.isKeyboardElement(ele) ).toEqual(false);
ele.type = 'week';
expect( ionic.tap.isKeyboardElement(ele) ).toEqual(false);

ele.type = 'time';
expect( ionic.tap.isKeyboardElement(ele) ).toEqual(false);
ele.type = 'time';
expect( ionic.tap.isKeyboardElement(ele) ).toEqual(false);

ele = document.createElement('select');
expect ( ionic.tap.isKeyboardElement(ele)).toEqual(false);
ele = {};
expect ( ionic.tap.isKeyboardElement(ele)).toEqual(false);

ionic.Platform.setPlatform('ios');
ionic.Platform.ua = 'iPad';
ionic.Platform.setPlatform('ios');
ionic.Platform.ua = 'iPad';

ele = document.createElement('input');
ele.type = 'date';
expect( ionic.tap.isKeyboardElement(ele) ).toEqual(false);
ele = {};
ele.type = 'date';
expect( ionic.tap.isKeyboardElement(ele) ).toEqual(false);

ele.type = 'datetime-local';
expect( ionic.tap.isKeyboardElement(ele) ).toEqual(false);
ele.type = 'datetime-local';
expect( ionic.tap.isKeyboardElement(ele) ).toEqual(false);

ele.type = 'month';
expect( ionic.tap.isKeyboardElement(ele) ).toEqual(false);
ele.type = 'month';
expect( ionic.tap.isKeyboardElement(ele) ).toEqual(false);

ele.type = 'week';
expect( ionic.tap.isKeyboardElement(ele) ).toEqual(false);
ele.type = 'week';
expect( ionic.tap.isKeyboardElement(ele) ).toEqual(false);

ele.type = 'time';
expect( ionic.tap.isKeyboardElement(ele) ).toEqual(false);
ele.type = 'time';
expect( ionic.tap.isKeyboardElement(ele) ).toEqual(false);

ele = document.createElement('select');
expect ( ionic.tap.isKeyboardElement(ele)).toEqual(false);
}
ele = {};
expect ( ionic.tap.isKeyboardElement(ele)).toEqual(false);
});

it('Should isLabelWithTextInput', function() {
Expand Down

0 comments on commit fbae1ab

Please sign in to comment.