Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ionicTabs#showBar() method to set/get whether the tabs bar is shown #4613

Merged
merged 1 commit into from Dec 6, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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