Skip to content

Commit

Permalink
feat(tab): options 'hidden' attribute for tabs. Closes #1666, #1673
Browse files Browse the repository at this point in the history
  • Loading branch information
perrygovier committed Jul 9, 2014
1 parent 208ef13 commit bb6976a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 5 deletions.
1 change: 1 addition & 0 deletions js/angular/directive/tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ function($rootScope, $animate, $ionicBind, $compile) {
attrStr('icon-off', attr.iconOff) +
attrStr('badge', attr.badge) +
attrStr('badge-style', attr.badgeStyle) +
attrStr('hidden', attr.hidden) +
attrStr('class', attr['class']) +
'></ion-tab-nav>';

Expand Down
8 changes: 7 additions & 1 deletion js/angular/directive/tabNav.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ IonicModule
replace: true,
require: ['^ionTabs', '^ionTab'],
template:
'<a ng-class="{\'tab-item-active\': isTabActive(), \'has-badge\':badge}" ' +
'<a ng-class="{\'tab-item-active\': isTabActive(), \'has-badge\':badge, \'tab-hidden\':isHidden()}" ' +
' class="tab-item">' +
'<span class="badge {{badgeStyle}}" ng-if="badge">{{badge}}</span>' +
'<i class="icon {{getIconOn()}}" ng-if="getIconOn() && isTabActive()"></i>' +
Expand All @@ -18,6 +18,7 @@ IonicModule
iconOn: '@',
iconOff: '@',
badge: '=',
hidden: '@',
badgeStyle: '@',
'class': '@'
},
Expand All @@ -41,6 +42,11 @@ IonicModule
});
}

$scope.isHidden = function() {
if($attrs.hidden === 'true' || $attrs.hidden === true)return true;
return false;
};

$scope.getIconOn = function() {
return $scope.iconOn || $scope.icon;
};
Expand Down
3 changes: 3 additions & 0 deletions scss/_tabs.scss
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@
&:hover {
cursor: pointer;
}
&.tab-hidden{
display:none;
}
}

.tabs-item-hide > .tabs,
Expand Down
11 changes: 10 additions & 1 deletion test/html/tabs.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@ <h1>Settings</h1>
</ion-content>
</ion-tab>

<ion-tab title="Hidden" icon-on="icon ion-ionic" icon-off="icon ion-ionic" hidden="true">
<header class="bar bar-header bar-positive">
<h1 class="title">Hidden Tab</h1>
</header>
<ion-content class="has-header" padding="true">
<h1>This tab should be hidden</h1>
</ion-content>
</ion-tab>

</ion-tabs>

<script id="newTask.html" type="text/ng-template">
Expand All @@ -111,7 +120,7 @@ <h1 class="title">New Task</h1>
</div>
</script>

<script>
<script type="text/javascript">
angular.module('tabsTest', ['ionic'])

.controller('RootCtrl', function($scope, $timeout) {
Expand Down
10 changes: 7 additions & 3 deletions test/unit/angular/directive/tabs.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,14 +419,15 @@ describe('tabs', function() {
});

it('should compile a <ion-tab-nav> with all of the relevant attrs', function() {
setup('title="{{a}}" icon-on="{{b}}" icon-off="{{c}}" badge="d" badge-style="{{e}}" class="{{f}}" ng-click="click"');
setup('title="{{a}}" icon-on="{{b}}" icon-off="{{c}}" badge="d" badge-style="{{e}}" class="{{f}}" ng-click="click" hidden="{{g}}"');
angular.extend(tabEl.scope(), {
a: 'title',
b: 'on',
c: 'off',
d: 6,
e: 'badger',
f: 'someClass'
f: 'someClass',
g: true
});
tabEl.scope().$apply();
var navItem = angular.element(tabsEl[0].querySelector('.tab-item'));
Expand All @@ -437,14 +438,16 @@ describe('tabs', function() {
expect(navItem.isolateScope().badgeStyle).toEqual('badger');
expect(navItem[0].className).toMatch(/someClass/);
expect(navItem.attr('ng-click')).toEqual('click');
expect(navItem.isolateScope().hidden).toEqual('true');

angular.extend(tabEl.scope(), {
a: 'title2',
b: 'on2',
c: 'off2',
d: 7,
e: 'badger2',
f: 'someClass2'
f: 'someClass2',
g: false
});
tabEl.scope().$apply();
expect(navItem.isolateScope().title).toEqual('title2');
Expand All @@ -453,6 +456,7 @@ describe('tabs', function() {
expect(navItem.isolateScope().badge).toEqual(7);
expect(navItem.isolateScope().badgeStyle).toEqual('badger2');
expect(navItem[0].className).toMatch(/someClass2/);
expect(navItem.isolateScope().hidden).toEqual('false');

expect(navItem.parent()[0]).toBe(tabsCtrl.$tabsElement[0]);
});
Expand Down

0 comments on commit bb6976a

Please sign in to comment.