Skip to content

Commit

Permalink
Merge pull request #4613 from ewdl/feature-tabs
Browse files Browse the repository at this point in the history
Add ionicTabs#showBar() method to set/get whether the tabs bar is shown
  • Loading branch information
mlynch committed Dec 6, 2015
2 parents dbd0d24 + 7dd620d commit 27fc24e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
12 changes: 12 additions & 0 deletions js/angular/controller/tabsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ function($scope, $element, $ionicHistory) {
var selectedTab = null;
var previousSelectedTab = null;
var selectedTabIndex;
var isVisible = true;
self.tabs = [];

self.selectedIndex = function() {
Expand Down Expand Up @@ -114,4 +115,15 @@ function($scope, $element, $ionicHistory) {
return false;
};

self.showBar = function (show) {
if (arguments.length) {
if (show) {
$element.removeClass('tabs-item-hide');
} else {
$element.addClass('tabs-item-hide');
}
isVisible = !!show;
}
return isVisible;
};
}]);
11 changes: 10 additions & 1 deletion js/angular/service/tabsDelegate.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,16 @@ IonicModule
* @name $ionicTabsDelegate#selectedIndex
* @returns `number` The index of the selected tab, or -1.
*/
'selectedIndex'
'selectedIndex',
/**
* @ngdoc method
* @name $ionicTabsDelegate#showBar
* @description
* Set/get whether the {@link ionic.directive:ionTabs} is shown
* @param {boolean} show Whether to show the bar.
* @returns {boolean} Whether the bar is shown.
*/
'showBar',
/**
* @ngdoc method
* @name $ionicTabsDelegate#$getByHandle
Expand Down
16 changes: 14 additions & 2 deletions test/unit/angular/directive/tabs.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ describe('tabs', function() {

describe('$ionicTabs controller', function() {
beforeEach(module('ionic'));
var ctrl, scope;
var ctrl, scope, $element;
beforeEach(inject(function($rootScope, $controller) {
scope = $rootScope.$new();
$element = angular.element('<div>');
ctrl = $controller('$ionicTabs', {
$scope: scope,
$element: angular.element('<div>')
$element: $element
});
}));

Expand Down Expand Up @@ -184,6 +185,17 @@ describe('tabs', function() {
uiSref: tab3.uiSref
});
});

it('.showBar with true/false should remove/add a tabs-item-hide class', function() {
var visible = ctrl.showBar();
expect(visible).toBe(true);
visible = ctrl.showBar(false);
expect(visible).toBe(false);
expect($element.hasClass('tabs-item-hide')).toBe(true);
visible = ctrl.showBar(true);
expect(visible).toBe(true);
expect($element.hasClass('tabs-item-hide')).toBe(false);
});
});

describe('ionTabs directive', function() {
Expand Down

0 comments on commit 27fc24e

Please sign in to comment.