Skip to content

Commit bb6976a

Browse files
committed
feat(tab): options 'hidden' attribute for tabs. Closes #1666, #1673
1 parent 208ef13 commit bb6976a

File tree

5 files changed

+28
-5
lines changed

5 files changed

+28
-5
lines changed

Diff for: js/angular/directive/tab.js

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ function($rootScope, $animate, $ionicBind, $compile) {
6868
attrStr('icon-off', attr.iconOff) +
6969
attrStr('badge', attr.badge) +
7070
attrStr('badge-style', attr.badgeStyle) +
71+
attrStr('hidden', attr.hidden) +
7172
attrStr('class', attr['class']) +
7273
'></ion-tab-nav>';
7374

Diff for: js/angular/directive/tabNav.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ IonicModule
55
replace: true,
66
require: ['^ionTabs', '^ionTab'],
77
template:
8-
'<a ng-class="{\'tab-item-active\': isTabActive(), \'has-badge\':badge}" ' +
8+
'<a ng-class="{\'tab-item-active\': isTabActive(), \'has-badge\':badge, \'tab-hidden\':isHidden()}" ' +
99
' class="tab-item">' +
1010
'<span class="badge {{badgeStyle}}" ng-if="badge">{{badge}}</span>' +
1111
'<i class="icon {{getIconOn()}}" ng-if="getIconOn() && isTabActive()"></i>' +
@@ -18,6 +18,7 @@ IonicModule
1818
iconOn: '@',
1919
iconOff: '@',
2020
badge: '=',
21+
hidden: '@',
2122
badgeStyle: '@',
2223
'class': '@'
2324
},
@@ -41,6 +42,11 @@ IonicModule
4142
});
4243
}
4344

45+
$scope.isHidden = function() {
46+
if($attrs.hidden === 'true' || $attrs.hidden === true)return true;
47+
return false;
48+
};
49+
4450
$scope.getIconOn = function() {
4551
return $scope.iconOn || $scope.icon;
4652
};

Diff for: scss/_tabs.scss

+3
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@
185185
&:hover {
186186
cursor: pointer;
187187
}
188+
&.tab-hidden{
189+
display:none;
190+
}
188191
}
189192

190193
.tabs-item-hide > .tabs,

Diff for: test/html/tabs.html

+10-1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,15 @@ <h1>Settings</h1>
9797
</ion-content>
9898
</ion-tab>
9999

100+
<ion-tab title="Hidden" icon-on="icon ion-ionic" icon-off="icon ion-ionic" hidden="true">
101+
<header class="bar bar-header bar-positive">
102+
<h1 class="title">Hidden Tab</h1>
103+
</header>
104+
<ion-content class="has-header" padding="true">
105+
<h1>This tab should be hidden</h1>
106+
</ion-content>
107+
</ion-tab>
108+
100109
</ion-tabs>
101110

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

114-
<script>
123+
<script type="text/javascript">
115124
angular.module('tabsTest', ['ionic'])
116125

117126
.controller('RootCtrl', function($scope, $timeout) {

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

+7-3
Original file line numberDiff line numberDiff line change
@@ -419,14 +419,15 @@ describe('tabs', function() {
419419
});
420420

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

441443
angular.extend(tabEl.scope(), {
442444
a: 'title2',
443445
b: 'on2',
444446
c: 'off2',
445447
d: 7,
446448
e: 'badger2',
447-
f: 'someClass2'
449+
f: 'someClass2',
450+
g: false
448451
});
449452
tabEl.scope().$apply();
450453
expect(navItem.isolateScope().title).toEqual('title2');
@@ -453,6 +456,7 @@ describe('tabs', function() {
453456
expect(navItem.isolateScope().badge).toEqual(7);
454457
expect(navItem.isolateScope().badgeStyle).toEqual('badger2');
455458
expect(navItem[0].className).toMatch(/someClass2/);
459+
expect(navItem.isolateScope().hidden).toEqual('false');
456460

457461
expect(navItem.parent()[0]).toBe(tabsCtrl.$tabsElement[0]);
458462
});

0 commit comments

Comments
 (0)