Skip to content

Commit

Permalink
Add ionicTabs#showBar() method to set/get whether the tabs bar is shown
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandre Laurent committed Nov 9, 2015
1 parent 3adb7fc commit 7dd620d
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

2 comments on commit 7dd620d

@mintzhao
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi, i am newer for ionic, i hide the tab in secondery ui, use showBar(false), but when i back, first ui's tab also hide. i use showBar(true) did not work, because first ui is cached, so, how can i easily use this?

@ladmerc
Copy link

@ladmerc ladmerc commented on 7dd620d Jul 5, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue as @Mint-Zhao-Chiu. Cached view still shows bar

Please sign in to comment.