Skip to content

Commit 7dd620d

Browse files
author
Alexandre Laurent
committed
Add ionicTabs#showBar() method to set/get whether the tabs bar is shown
1 parent 3adb7fc commit 7dd620d

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

Diff for: js/angular/controller/tabsController.js

+12
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ function($scope, $element, $ionicHistory) {
88
var selectedTab = null;
99
var previousSelectedTab = null;
1010
var selectedTabIndex;
11+
var isVisible = true;
1112
self.tabs = [];
1213

1314
self.selectedIndex = function() {
@@ -114,4 +115,15 @@ function($scope, $element, $ionicHistory) {
114115
return false;
115116
};
116117

118+
self.showBar = function (show) {
119+
if (arguments.length) {
120+
if (show) {
121+
$element.removeClass('tabs-item-hide');
122+
} else {
123+
$element.addClass('tabs-item-hide');
124+
}
125+
isVisible = !!show;
126+
}
127+
return isVisible;
128+
};
117129
}]);

Diff for: js/angular/service/tabsDelegate.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,16 @@ IonicModule
4848
* @name $ionicTabsDelegate#selectedIndex
4949
* @returns `number` The index of the selected tab, or -1.
5050
*/
51-
'selectedIndex'
51+
'selectedIndex',
52+
/**
53+
* @ngdoc method
54+
* @name $ionicTabsDelegate#showBar
55+
* @description
56+
* Set/get whether the {@link ionic.directive:ionTabs} is shown
57+
* @param {boolean} show Whether to show the bar.
58+
* @returns {boolean} Whether the bar is shown.
59+
*/
60+
'showBar',
5261
/**
5362
* @ngdoc method
5463
* @name $ionicTabsDelegate#$getByHandle

Diff for: test/unit/angular/directive/tabs.unit.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ describe('tabs', function() {
22

33
describe('$ionicTabs controller', function() {
44
beforeEach(module('ionic'));
5-
var ctrl, scope;
5+
var ctrl, scope, $element;
66
beforeEach(inject(function($rootScope, $controller) {
77
scope = $rootScope.$new();
8+
$element = angular.element('<div>');
89
ctrl = $controller('$ionicTabs', {
910
$scope: scope,
10-
$element: angular.element('<div>')
11+
$element: $element
1112
});
1213
}));
1314

@@ -184,6 +185,17 @@ describe('tabs', function() {
184185
uiSref: tab3.uiSref
185186
});
186187
});
188+
189+
it('.showBar with true/false should remove/add a tabs-item-hide class', function() {
190+
var visible = ctrl.showBar();
191+
expect(visible).toBe(true);
192+
visible = ctrl.showBar(false);
193+
expect(visible).toBe(false);
194+
expect($element.hasClass('tabs-item-hide')).toBe(true);
195+
visible = ctrl.showBar(true);
196+
expect(visible).toBe(true);
197+
expect($element.hasClass('tabs-item-hide')).toBe(false);
198+
});
187199
});
188200

189201
describe('ionTabs directive', function() {

0 commit comments

Comments
 (0)